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.
Performance improvements:
1) Primes starting with 8 or 9 will not yield to a prime after stipping R to L.
2) Don't count primes 2,3,5,7 sum-17 is faster than primes.Skip(4)
Problem37 = 748317 elapsed time: 12 ms. Test Passed.
Geen opmerkingen:
Een reactie posten