Find largest left truncatable prime in a given base: Difference between revisions
Content added Content deleted
m (added whitespace before the TOC (table of contents).) |
(→{{header|Tcl}}: added zkl) |
||
Line 1,231: | Line 1,231: | ||
</pre> |
</pre> |
||
I think I'll need to find a faster computer to calculate much more of the sequence, but memory consumption is currently negligible so there's no reason to expect there to be any major problems. |
I think I'll need to find a faster computer to calculate much more of the sequence, but memory consumption is currently negligible so there's no reason to expect there to be any major problems. |
||
=={{header|zkl}}== |
|||
<lang zkl>var [const] BN=Import("zklBigNum"); // libGMP |
|||
fcn largest_lefty_prime(base){ |
|||
primes,p:=List(),BN(1); while(p.nextPrime()<base){ primes.append(p.copy()) } |
|||
b,biggest := BN(1),0; |
|||
while(primes){ |
|||
b.mul(base); // base,base^2,base^3... |
|||
ps:=List(); |
|||
foreach p,n in (primes,[1..base-1]){ |
|||
if((z:=(p + b*n)).probablyPrime()){ |
|||
ps.append(z); |
|||
if(biggest<z) biggest=z; |
|||
} |
|||
} |
|||
primes=ps; // the number of lists is small |
|||
} |
|||
biggest |
|||
} |
|||
foreach n in ([3..17]){ println("%2d %s".fmt(n,largest_lefty_prime(n))) }</lang> |
|||
I've included 18,19 & 20 here but 18 & 20 are very very slow to compute, it is seconds to compute all the others. |
|||
{{out}} |
|||
<pre> |
|||
3 23 |
|||
4 4091 |
|||
5 7817 |
|||
6 4836525320399 |
|||
7 817337 |
|||
8 14005650767869 |
|||
9 1676456897 |
|||
10 357686312646216567629137 |
|||
11 2276005673 |
|||
12 13092430647736190817303130065827539 |
|||
13 812751503 |
|||
14 615419590422100474355767356763 |
|||
15 34068645705927662447286191 |
|||
16 1088303707153521644968345559987 |
|||
17 13563641583101 |
|||
18 571933398724668544269594979167602382822769202133808087 |
|||
19 546207129080421139 |
|||
20 1073289911449776273800623217566610940096241078373 |
|||
</pre> |