mersenneforum.org  

Go Back   mersenneforum.org > Fun Stuff > Puzzles

Reply
 
Thread Tools
Old 2015-05-12, 15:14   #1
petrw1
1976 Toyota Corona years forever!
 
petrw1's Avatar
 
"Wayne"
Nov 2006
Saskatchewan, Canada

124416 Posts
Default Just dreamed this one up....

What is the largest prime number you can find such that all groupings of numbers in order are also prime....
For example in the prime 373 all the following in () are also prime
(3)73, 3(7)3, 37(3), (37)3, 3(73)

Obviously it can only contain the digits 2, 3, 5, 7

I believe the first 5 non-trivial are:
23, 37, 53, 73, 373,
petrw1 is offline   Reply With Quote
Old 2015-05-12, 15:49   #2
axn
 
axn's Avatar
 
Jun 2003

22×3×421 Posts
Default

Quote:
Originally Posted by petrw1 View Post
I believe the first 5 non-trivial are:
23, 37, 53, 73, 373,
And those are the only solutions :-(

To create an n-digit solution, you need an n-1 digit solution and extend it by prefixing or suffixing another digit.
2 and 5 can only go as leading digit.
Same digit cannot occur consecutively.

With these restrictions, we see that the four 2-digit solutions and the one 3-digit solution are the only ones possible. 373 is a dead end. It cannot be extended further.
axn is online now   Reply With Quote
Old 2015-05-12, 16:32   #3
petrw1
1976 Toyota Corona years forever!
 
petrw1's Avatar
 
"Wayne"
Nov 2006
Saskatchewan, Canada

22·7·167 Posts
Default Guess I should have thought about this more first....

...
petrw1 is offline   Reply With Quote
Old 2015-05-12, 18:14   #4
Antonio
 
Antonio's Avatar
 
"Antonio Key"
Sep 2011
UK

32·59 Posts
Default

I offer 1373

(Ok, so I know 1 isn't strictly prime, but then it's not composite so there are no composites in any of the groupings.)

Last fiddled with by Antonio on 2015-05-12 at 18:17
Antonio is offline   Reply With Quote
Old 2015-05-12, 18:15   #5
legendarymudkip
 
legendarymudkip's Avatar
 
Jun 2014

23×3×5 Posts
Default

Quote:
Originally Posted by Antonio View Post
I offer 1373
(1)373 - 1 is not prime.
legendarymudkip is offline   Reply With Quote
Old 2015-05-12, 18:22   #6
Antonio
 
Antonio's Avatar
 
"Antonio Key"
Sep 2011
UK

32·59 Posts
Default

Quote:
Originally Posted by legendarymudkip View Post
(1)373 - 1 is not prime.
Oops, replied while I was editing in the last sentence.
Antonio is offline   Reply With Quote
Old 2015-05-15, 14:53   #7
LaurV
Romulan Interpreter
 
LaurV's Avatar
 
Jun 2011
Thailand

961110 Posts
Default

Actually, let's allow 1 into it, to make it a bit more.. attractive. This way, you can have a 1 here and there, and even two of 1, as 11, 13, 17, 31, 71, are all prime... How high can you go?
LaurV is offline   Reply With Quote
Old 2015-05-15, 17:07   #8
petrw1
1976 Toyota Corona years forever!
 
petrw1's Avatar
 
"Wayne"
Nov 2006
Saskatchewan, Canada

22×7×167 Posts
Default ok....next....

3137

your turn...hint no more of 4-digits

Last fiddled with by petrw1 on 2015-05-15 at 17:13
petrw1 is offline   Reply With Quote
Old 2015-05-16, 09:07   #9
LaurV
Romulan Interpreter
 
LaurV's Avatar
 
Jun 2011
Thailand

7×1,373 Posts
Default

Ha! I made you lose 20 minutes from your DC time! Every time you lose is a gain for me, so I can overtake you in the DC top..

Joking apart (not!), I was too lazy/stupid to think (and anyhow one needs a calculator/computer to check the primality of 4-digits and more numbers), so I decided to write a pari/gp script, which took me about the same amount of time.

Unfortunately I can't argue against you since my script says you are right... what a pity...
These are all the solutions:
Code:
gp > \r digits
%xx = List([1, 2, 3, 5, 7])
time = 4 ms.
%xx = List([1, 2, 3, 5, 7, 11, 13, 17, 23, 31, 37, 53, 71, 73, 113, 131, 137, 173, 311, 313, 317, 373, 1373, 3137])
gp >
Here is the script to which I spent some more time to beautify and print the intermediary steps, you can directly paste it into the pari screen (or save it in a separate file) if you want to play with it (i.e lose even more time apart from the DC tasks... :hehe:)

Code:
adg(digit=1, size=1)=
{
    my(cnt=0,k,n,t,isp,ls);
    
    for(i=1,#glist,
        n=glist[i];
        if(10^(size-1)<=n && n<10^size,
        
            /*add on the back*/
            k=1;
            isp=1;
            while(isp && k<=n,
                k*=10;
                if(!isprime((n%k)*10+digit),
                    isp=0
                )
            );
            
            if(isp,
                ls=#glist;
                listput(glist,n*10+digit);
                listsort(glist,1);
                if(ls!=#glist,
                    cnt++
                )
            );
            
            /* add on the front */
            k=ceil(log(n)/log(10));
            if(n==1,k=1);
            t=k;
            isp=1;
            while(isp && k>0,
                if(!isprime(digit*10^k+floor(n/10^(t-k))),
                    isp=0
                );
                k--
            );
            if(isp,
                ls=#glist;
                listput(glist,digit*10^t+n);
                listsort(glist,1);
                if(ls!=#glist,
                    cnt++
                )
            )
        )
    );
    cnt
};

adigi(maxsize=8)=
{
    my(s,ls);
    for(size=1,maxsize,
        until(s==0,
            s=0;
            forstep(i=1,7,2,
                ls=#glist;
                s=max(s,adg(i,size));
                if(ls!=#glist,
                    print(glist)
                )
            );
            ls=#glist;
            s=max(s,adg(2,size));
            if(ls!=#glist,
                print(glist)
            )
        )
    )
};

glist=List([1,2,3,5,7])
adigi()
glist

Last fiddled with by LaurV on 2015-05-16 at 09:08
LaurV is offline   Reply With Quote
Reply



All times are UTC. The time now is 03:29.


Sat Jul 17 03:29:57 UTC 2021 up 50 days, 1:17, 1 user, load averages: 1.47, 1.53, 1.46

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.