Truncatable primes: Difference between revisions
Content deleted Content added
Pari/GP |
m →{{header|PARI/GP}}: correction |
||
Line 373: | Line 373: | ||
This version builds the truncatable primes with up to k digits in a straightforward fashion. Run time is about 15 milliseconds, almost all of which is I/O. |
This version builds the truncatable primes with up to k digits in a straightforward fashion. Run time is about 15 milliseconds, almost all of which is I/O. |
||
<lang>left(n)={ |
<lang>left(n)={ |
||
my(v=[2,3,5,7],u,t=1); |
my(v=[2,3,5,7],u,t=1,out=0); |
||
for(i=1,n, |
for(i=1,n, |
||
t*=10; |
t*=10; |
||
u=[]; |
u=[]; |
||
for(j=1,#v, |
for(j=1,#v, |
||
print1(v[j]","); |
|||
forstep(a=t,t*9,t, |
forstep(a=t,t*9,t, |
||
if(isprime(a+v[j]),u=concat(u,a+v[j])) |
if(isprime(a+v[j]),u=concat(u,a+v[j])) |
||
) |
) |
||
); |
); |
||
out=v[#v]; |
|||
v=u |
v=u |
||
) |
); |
||
out |
|||
}; |
}; |
||
right(n)={ |
right(n)={ |
||
my(v=[2,3,5,7],u); |
my(v=[2,3,5,7],u,out=0); |
||
for(i=1,n, |
for(i=1,n, |
||
u=[]; |
u=[]; |
||
for(j=1,#v, |
for(j=1,#v, |
||
print1(v[j]","); |
|||
forstep(a=1,9,[2,4], |
forstep(a=1,9,[2,4], |
||
if(isprime(10*v[j]+a),u=concat(u,10*v[j]+a)) |
if(isprime(10*v[j]+a),u=concat(u,10*v[j]+a)) |
||
) |
) |
||
); |
); |
||
out=v[#v]; |
|||
v=u |
v=u |
||
) |
); |
||
out |
|||
}; |
}; |
||
left(6) |
[left(6),right(6)]</lang> |
||
=={{header|Perl 6}}== |
=={{header|Perl 6}}== |