The number 3797 has an interesting property. Being prime itself, it is possible to continuously remove digits from left to right, and remain prime at each stage: 3797, 797, 97, and 7. Similarly we can work from right to left: 3797, 379, 37, and 3.
Find the sum of the only eleven primes that are both truncatable from left to right and right to left.
NOTE: 2, 3, 5, and 7 are not considered to be truncatable primes.
Interesting problem. It's important to note that primes can containing even number digits. However, for prime to be truncatable prime, it can't contain even numbers. For example, if we truncate 579141, we start off with 1. Then, the 57914 is not a prime. This works for all even numbers except 2. For example, 235791 can truncated to 2, but 2 is a prime. But we ignore this exception. The method is pretty simple. Start from two-digit prime, greater than 23. 23 works, but we do not take into account in this code. When we find such prime, we add one to a variable and keep searching until we hit 11!
Notice that in my code I have variables that will only allow 1, 3, 5, 7, 9 to be digits of the prime. Also, I have two for loops checking this a prime: One direction truncating left to right, and another going right to left. Both need to be required.
Answer: 748317
Runtime: 26.4 seconds