Download or view leftTruncatablePrimes.frink in plain text format
/** This program finds left-truncatable primes, that is, prime numbers that
always produce prime numbers when their leftmost digit is chopped off.
This builds them from a starting set of primes and will find all
left-truncatable primes. Zero is not allowed as a digit in this
formulation, which produces a finite number of solutions.
*/
testPrime[nums] :=
{
result = new array
for d = [1,2,3,4,5,6,7,8,9]
{
for n = nums
{
c = parseInt["$d$n"]
if isPrime[c] and c != 1
result.push[c]
}
}
return result
}
results = [1,2,3,5,7]
digits = 1
while (length[results] != 0)
{
newresults = new array
newresults = testPrime[results]
println["$digits\t" + length[newresults] + "\t" + newresults]
results = newresults
digits = digits + 1
}
Download or view leftTruncatablePrimes.frink in plain text format
This is a program written in the programming language Frink.
For more information, view the Frink
Documentation or see More Sample Frink Programs.
Alan Eliasen was born 20139 days, 6 hours, 24 minutes ago.