/** 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 }