matryoprimes.py 457 B

1234567891011121314151617181920212223
  1. # Find all the Russian Doll primes for a given base
  2. # Author: estelendur
  3. def isPrime(x):
  4. # insert primality test here
  5. def encase(primes):
  6. new = []
  7. app = [1, 3, 7, 9]
  8. for p in primes:
  9. for a in app:
  10. i = p*10+a
  11. if isPrime(i):
  12. new.append(i)
  13. if len(new) > 0:
  14. return primes + encase(new)
  15. else:
  16. return
  17. def dollPrimes():
  18. oned = [2, 3, 5, 7]
  19. return encase(oned)