All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars
 perplexus dot info

 Mirror, mirror (Posted on 2012-05-04)
What palindromic prime number of n digits reads the same upside down or when viewed in a mirror?

Some examples for n=2 or 3:
11, 101, 181.

How far can you go?

Rem: Only digits 0,l and 8 qualify.

Comments: ( Back to comment list | You must be logged in to post comments.)
 computer solution | Comment 3 of 4 |

4   kill "mirrmir3.txt"
5   open "mirrmir3.txt" for output as #2
10   No2="1"
25   close #2
30   end
40   '
60   No2=No2+"0"
70   gosub *TestNo2
80   if len(No2)<13 then gosub *AddOn
90   No2=left(No2,len(No2)-1)+"1"
100   gosub *TestNo2
110   if len(No2)<13 then gosub *AddOn
120   No2=left(No2,len(No2)-1)+"8"
130   gosub *TestNo2
140   if len(No2)<13 then gosub *AddOn
150   No2=left(No2,len(No2)-1)
160   return
170
180   *TestNo2
190   Tst=No2
200   for I=len(No2)-1 to 1 step -1
210     Tst=Tst+mid(No2,I,1)
220   next I
230   if fnPrime(val(Tst)) then print #2,spc(27-len(Tst))+Tst
240   return
300
10000   fnOddfact(N)
10010   local K=0,P
10030   while N@2=0
10040     N=N\2
10050     K=K+1
10060   wend
10070   P=pack(N,K)
10080   return(P)
10090   '
10100   fnPrime(N)
10110   local I,X,J,Y,Q,K,T,Ans
10120   if N@2=0 then Ans=0:goto *EndPrime
10125   O=fnOddfact(N-1)
10130   Q=member(O,1)
10140   K=member(O,2)
10150   I=0
10160   repeat
10170     repeat
10180       X=fnLrand(N)
10190     until X>1
10200     J=0
10210     Y=modpow(X,Q,N)
10220     loop
10230       if or{and{J=0,Y=1},Y=N-1} then goto *ProbPrime
10240       if and{J>0,Y=1} then goto *NotPrime
10250       J=J+1
10260       if J=K then goto *NotPrime
10270       Y=(Y*Y)@N
10280     endloop
10290    *ProbPrime
10300     I=I+1
10310   until I>50
10320   Ans=1
10330   goto *EndPrime
10340   *NotPrime
10350   Ans=0
10360   *EndPrime
10370   return(Ans)
10380   '
10400   fnLrand(N)
10410   local R
10415   N=int(N)
10420   R=(int(rnd*10^(alen(N)+2)))@N
10430   return(R)
10440   '

finds 36,499 odd-length such primes up through length 25. The only even-length palindromic prime is 11, as all even-length palindromes are divisible by 11. So, adding in that one prime, makes 36,500 such primes through length 25.

The program uses a probabilistic prime test that makes it astronomically unlikely that a composite will be declared prime.

The list was created in lexicographic order and then the file was sorted into numeric order. I'll try to get up through the 17-digit ones to list here:

`                        101                        181                      18181                    1008001                    1180811                    1880881                    1881881                  100111001                  100888001                  108101801                  110111011                  111010111                  111181111                  118818811                  180101081                  181111181                  181888181                  188010881                  188888881                10008180001                10081818001                10101810101                10180008101                10180808101                10181018101                10810001801                10880108801                11008080011                11088888011                11100800111                11188888111                11800000811                11880108811                11881018811                11881818811                11888088811                18001010081                18018881081                18081818081                18110001181                18111111181                18118881181                18180808181                18810101881                18818181881              1000008000001              1000180810001              1000188810001              1008008008001              1008100018001              1008800088001              1010088800101              1010181810101              1010810180101              1018101018101              1018808088101              1080008000801              1080081800801              1081088801801              1081810181801              1088800088801              1100011100011              1100018100011              1100080800011              1100101010011              1100118110011              1100881880011              1101008001011              1101010101011              1101081801011              1101181811011              1101188811011              1101880881011              1108088808011              1108881888011              1110110110111              1110111110111              1110811180111              1110880880111              1111008001111              1111118111111              1111188811111              1118011108111              1118888888111              1180000000811              1180010100811              1180818180811              1181018101811              1188811188811              1800010100081              1800018100081              1800818180081              1801008001081              1801088801081              1801808081081              1801880881081              1808110118081              1810008000181              1810100010181              1811018101181              1880000000881              1880108010881              1880808080881              1881008001881              1881100011881              1881800081881              1888081808881            100008101800001            100018080810001            100081101180001            100100888001001            100108818801001            100110101011001            100110808011001            100118808811001            100181111181001            100181181181001            100188080881001            100800818008001            100801000108001            100808181808001            100810080018001            100818080818001            100881080188001            100888111888001            100888818888001            101000010000101            101010080010101            101011000110101            101011888110101            101018000810101            101080888080101            101081888180101            101110000011101            101110818011101            101118010811101            101188101881101            101800080008101            101800101008101            101800818008101            101801181108101            101801808108101            101810181018101            101811010118101            101811808118101            101888010888101            108000181000801            108001111100801            108008000800801            108008808800801            108010080010801            108081181180801            108100080001801            108100101001801            108108010801801            108108101801801            108110000011801            108110888011801            108188808881801            108800181008801            108800808008801            108881010188801            108888010888801            110000808000011            110000888000011            110011101110011            110018010810011            110080111080011            110081181180011            110081808180011            110108808801011            110118818811011            110180111081011            110188888881011            110800818008011            110800888008011            110808080808011            110808808808011            110810888018011            110880818088011            110881000188011            111001888100111            111008010800111            111008808800111            111008888800111            111010888010111            111011808110111            111011888110111            111088000880111            111088080880111            111100111001111            111101888101111            111111181111111            111180181081111            111181080181111            111188111881111            111188181881111            111188888881111            111800181008111            111801101108111            111810181018111            111810808018111            111880101088111            111881010188111            111888181888111            118000000000811            118000101000811            118010000010811            118011181110811            118011818110811            118018080810811            118018101810811            118018818810811            118088181880811            118100111001811            118101101101811            118111080111811            118118111811811            118118181811811            118800101008811            118808888808811            118811808118811            118818010818811            118818101818811            118818181818811            118881080188811            118881808188811            180000010000081            180000808000081            180001101100081            180001888100081            180008808800081            180011808110081            180088888880081            180100080001081            180100101001081            180101808101081            180108080801081            180108808801081            180118000811081            180180080081081            180180101081081            180800111008081            180801101108081            180810080018081            180811000118081            180880888088081            181000888000181            181011808110181            181081888180181            181110101011181            181110808011181            181111818111181            181188818881181            181800080008181            181801818108181            181811111118181            181818818818181            188001101100881            188010080010881            188010181010881            188011111110881            188011818110881            188018888810881            188081000180881            188081888180881            188100101001881            188108111801881            188110101011881            188110111011881            188118818811881            188180181081881            188181101181881            188188111881881            188808080808881            188818111818881            188818888818881            188881111188881            188881818188881            188888888888881          10000010101000001          10000181018100001          10000188188100001          10000800800800001          10000801010800001          10000818181800001          10000888088800001          10000888888800001          10001808880810001          10008000800080001          10008008080080001          10008011011080001          10008101010180001          10008810101880001          10008811811880001          10008880008880001          10010008080001001          10010088888001001          10010100800101001          10010801010801001          10011001810011001          10011010001011001          10011080108011001          10011088088011001          10011118881111001          10011808080811001          10011811011811001          10011888888811001          10018180008181001          10018811111881001          10018818881881001          10018888888881001          10080000100008001          10080001010008001          10080001810008001          10080100000108001          10080180808108001          10080810101808001          10080818181808001          10081000000018001          10081001110018001          10081081018018001          10081108080118001          10081810001818001          10088080808088001          10088081018088001          10088180008188001          10088801110888001          10088811111888001          10088818081888001          10100081018000101          10100081118000101          10100110001100101          10100110801100101          10101001810010101          10101180808110101          10101888188810101          10108001010080101          10108018881080101          10108108080180101          10108800800880101          10108880108880101          10110001810001101          10110010001001101          10110088888001101          10110101110101101          10110108880101101          10110811811801101          10110880008801101          10111000000011101          10111101110111101          10111110101111101          10111880008811101          10118001110081101          10118010801081101          10180080108008101          10180080808008101          10180088088008101          10180808180808101          10180810001808101          10181011811018101          10188001010088101          10188011011088101          10188018181088101          10188101110188101          10188118081188101          10188180808188101          10188810101888101          10188818081888101          10800008180000801          10800110001100801          10800118081100801          10800181018100801          10801000800010801          10801001110010801          10801011811010801          10801100000110801          10801180808110801          10801800100810801          10801801010810801          10801811011810801          10801888888810801          10808008880080801          10808180108180801          10808181118180801          10808188088180801          10808800000880801          10808810101880801          10808880808880801          10808881018880801          10810008880001801          10810011811001801          10810081818001801          10810100100101801          10810101810101801          10810118181101801          10810800100801801          10811001110011801          10811008880011801          10811010801011801          10811108180111801          10811818081811801          10811881018811801          10818000800081801          10818008080081801          10818088088081801          10818808880881801          10818880808881801          10880010101008801          10880011011008801          10880080808008801          10880101010108801          10880118181108801          10880801110808801          10880811811808801          10881018181018801          10881088888018801          10881100000118801          10881110001118801          10881880008818801          10881881018818801          10888010101088801          10888108880188801          11000081118000011          11000188888100011          11000800000800011          11000800800800011          11000810101800011          11000888088800011          11000888188800011          11001010801010011          11001100800110011          11001111811110011          11001118081110011          11001801810810011          11008000000080011          11008100100180011          11008110101180011          11008810801880011          11008880008880011          11010000800001011          11010001010001011          11010081118001011          11010180108101011          11010880808801011          11011118081111011          11011801010811011          11011818181811011          11011881118811011          11018008880081011          11018188088181011          11018881818881011          11080080808008011          11080101110108011          11080180008108011          11081080008018011          11081088188018011          11081880108818011          11081888188818011          11088008080088011          11088011111088011          11088110101188011          11088188088188011          11088880808888011          11100088088000111          11100110001100111          11100188188100111          11101000800010111          11101008880010111          11101018881010111          11101088088010111          11108818081880111          11110118081101111          11110188188101111          11110888888801111          11111011811011111          11111081118011111          11111118881111111          11111801110811111          11111808180811111          11118001010081111          11118008180081111          11118010001081111          11180000100008111          11180110801108111          11180188088108111          11181000800018111          11181010801018111          11181101110118111          11181118881118111          11181888188818111          11188000800088111          11188080108088111          11188101110188111          11188108880188111          11800081818000811          11800088088000811          11800801010800811          11800810001800811          11801001110010811          11801010101010811          11801800000810811          11801808180810811          11801810001810811          11808001010080811          11808018181080811          11808081118080811          11810000000001811          11810010801001811          11810080808001811          11810081018001811          11810118881101811          11810801110801811          11810818881801811          11811010801011811          11811018181011811          11811111111111811          11811118881111811          11811811811811811          11811818181811811          11818001110081811          11818011811081811          11818088188081811          11818111811181811          11818801010881811          11818801810881811          11818808080881811          11818808180881811          11818818181881811          11818818881881811          11880101110108811          11880108880108811          11880801110808811          11881008180018811          11881011111018811          11881810001818811          11888008880088811          11888081118088811          11888101010188811          11888800800888811          11888811811888811          11888818881888811          18000000100000081          18000001010000081          18000818181800081          18000888188800081          18001008180010081          18001008880010081          18001010001010081          18001111811110081          18001188188110081          18001188888110081          18001810801810081          18008118181180081          18008180108180081          18008181118180081          18008880808880081          18010001110001081          18010008880001081          18010010101001081          18010011811001081          18010088088001081          18010088188001081          18010101110101081          18010101810101081          18010181018101081          18011008080011081          18011011811011081          18011081118011081          18011180108111081          18011181118111081          18011811111811081          18018008080081081          18018008180081081          18018100000181081          18018111811181081          18018118081181081          18018181818181081          18018188188181081          18018800100881081          18018808080881081          18018880808881081          18080800000808081          18080810101808081          18081081118018081          18081180108118081          18081810801818081          18081811811818081          18081888188818081          18088011811088081          18088018881088081          18088111011188081          18088181018188081          18088800100888081          18088808080888081          18088880008888081          18100011811000181          18100088088000181          18100111811100181          18100118181100181          18100818181800181          18101808180810181          18101880108810181          18101881018810181          18108000800080181          18108008080080181          18108011011080181          18110080008001181          18110111011101181          18110188088101181          18110810101801181          18111080108011181          18111088088011181          18111808880811181          18111811811811181          18111880008811181          18118000000081181          18118010001081181          18118088188081181          18118118181181181          18118181118181181          18180000800008181          18180011011008181          18180081118008181          18180108880108181          18180118881108181          18180181818108181          18180810101808181          18180811811808181          18180888188808181          18181008180018181          18181080808018181          18188010801088181          18188011011088181          18188011811088181          18188018081088181          18800081118000881          18800100800100881          18800110001100881          18800118881100881          18800188888100881          18800801010800881          18800811111800881          18800818881800881          18801001810010881          18801088088010881          18808008880080881          18808011111080881          18808088188080881          18808880108880881          18808888088880881          18810101110101881          18810111811101881          18810801810801881          18810818081801881          18810880808801881          18811108080111881          18811801810811881          18818101810181881          18818808880881881          18880108880108881          18880110101108881          18880111011108881          18880188888108881          18880818181808881          18880888088808881          18881011011018881          18881088888018881          18888001810088881          18888008180088881          18888080008088881          18888108880188881`

 Posted by Charlie on 2012-05-04 13:02:36

 Search: Search body:
Forums (0)