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

Home > Numbers
Pidigital primes (Posted on 2013-08-15) Difficulty: 3 of 5
A pidigital prime is an n-digit number whose digits are the first n digits of pi=3.141592... in some order. For example, 13 is a pidigital prime. Find all pidigital primes less than 10000000.

No Solution Yet Submitted by Math Man    
No Rating

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

I had originally misinterpreted this and thought the digits had to be in the correct order. That would have meant that 3, 31 and 314159 would have been the only ones that fit the under-10000000 criterion, as the next higher such number would be 31415926535897932384626433832795028841.

However, the digits, as in 13, need only be "in some order". That yields 426 pidigital primes:

3
31
13
431
31541
34511
35141
41351
41513
43151
45131
51341
51413
51431
53411
54311
13451
14153
15413
314159
314591
319541
341951
354911
391451
395141
413159
413951
415319
415391
415931
419351
419513
435191
439511
453119
459113
491531
495113
511439
513419
519413
539141
541193
541391
543911
591341
591431
593141
594311
911453
914351
914513
915143
934151
941153
941351
941513
943511
951341
951413
954131
114593
134591
134951
141359
141539
143159
143519
145139
145193
145391
145931
149153
149351
149531
153941
159431
191453
193451
193541
195341
195413
3142519
3142591
3149521
3159421
3192451
3211459
3241159
3249151
3411259
3412159
3415219
3421591
3511429
3524119
3541921
3592411
3594121
3912451
3915421
3921451
3951421
3954211
4112539
4113259
4115239
4121539
4123591
4132159
4132591
4135921
4151239
4152139
4153291
4159231
4192351
4193251
4195231
4211593
4213159
4213519
4213591
4215193
4215319
4219513
4251931
4259113
4259131
4295113
4295131
4311529
4312519
4315219
4315921
4325119
4329151
4351219
4391521
4392151
4511293
4511329
4512931
4513921
4519231
4523191
4532191
4539121
4592131
4911523
4912351
4923151
4935121
4951213
4951231
4952113
4953121
5114293
5119423
5121439
5121943
5123491
5131249
5134219
5142913
5143291
5143921
5191243
5193421
5194213
5213419
5213491
5213941
5219143
5231491
5239411
5241319
5241931
5243911
5291413
5291431
5294131
5312491
5319241
5319421
5321419
5324191
5329141
5341291
5349121
5392141
5392411
5411239
5412391
5412931
5413129
5419213
5421193
5423191
5429131
5431219
5431291
5432191
5491231
5493211
5913241
5913421
5914123
5921413
5921431
5932141
5932411
5934121
5934211
5941213
5941231
5941321
5942113
9124153
9125143
9125341
9145321
9151243
9154231
9214351
9214531
9231451
9235141
9245311
9251413
9315421
9321451
9321541
9342511
9351421
9352411
9415213
9421351
9423511
9425113
9453211
9511423
9512413
9521341
9523141
9531421
9534211
1124593
1135429
1142359
1142539
1142593
1143529
1145293
1145329
1152493
1153249
1153429
1154239
1159243
1159423
1192453
1194253
1214593
1215349
1215439
1219453
1231459
1234951
1235149
1235419
1243951
1249531
1254193
1259143
1259413
1291453
1293541
1294351
1312459
1314259
1321459
1321549
1324159
1324591
1324951
1325419
1325491
1325941
1329541
1341259
1342519
1342591
1345129
1345921
1349251
1351249
1352149
1352419
1354291
1392451
1392541
1394251
1412539
1423159
1425139
1425913
1429531
1432591
1435129
1435219
1435921
1439521
1452193
1453129
1459123
1495231
1495321
1512493
1512943
1513429
1514329
1519423
1523419
1523491
1523941
1524139
1524319
1524931
1529413
1534219
1534921
1541923
1542193
1543291
1549213
1549321
1592341
1592431
1593421
1594123
1912453
1912543
1915423
1924513
1925431
1934521
1941253
1942153
1943251
1952413
1954231
2113459
2115493
2115943
2134519
2139541
2141593
2145193
2149351
2151349
2151943
2153149
2153419
2153491
2154193
2154319
2154913
2154931
2194351
2194531
2195341
2311549
2314591
2314951
2315149
2315491
2341159
2351149
2351941
2391451
2391541
2394151
2395411
2411593
2413519
2413951
2415319
2415913
2431519
2435119
2435911
2439511
2451913
2453119
2459311
2491351
2493511
2511349
2511493
2513941
2514139
2514931
2541391
2549311
2591143
2593141
2594131
2911453
2911543
2913451
2913541
2915413
2915431
2934511
2935411
2941531
2951341
2951413
2953141
2953411
2954113
3115249
3115429
3124519

    5   point 6:kill "pidigitl.txt":open "pidigitl.txt" for output as #2
   10   Pistr=cutspc(str(#pi))
   20   Pistr=left(Pistr,1)+mid(Pistr,3,*)
   25   Pistr=left(Pistr,7)
   30   for L=1 to len(Pistr)
   40     Ns=left(Pistr,L):H=Ns
   50     repeat
   55       if fnPrime(val(Ns)) then print #2,Ns:Ct=Ct+1
   60       gosub *Permute(&Ns)
   65     until H=Ns
   80   next
   90   print Ct:close #2:end

...  (permute subroutine is a puzzle elsewhere on the site)

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   '
10500   fnNxprime(X)
10510   if X@2=0 then X=X+1
10520   while fnPrime(X)=0
10530     X=X+2
10540   wend
10550   return(X)
10560   '


  Posted by Charlie on 2013-08-15 19:26:45
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (2)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2017 by Animus Pactum Consulting. All rights reserved. Privacy Information