Initial commit

This commit is contained in:
Kevin Keogh
2018-07-02 15:45:49 -04:00
parent 60b3954a3b
commit fd817f8811
28 changed files with 809 additions and 0 deletions

25
problem-41.py Normal file
View File

@@ -0,0 +1,25 @@
MAX_NUM = 987654321
def sieve_of_eratosthenes(limit):
a = [True] * limit # Initialize the primality list
a[0] = a[1] = False
for (i, isprime) in enumerate(a):
if isprime:
yield i
for n in range(i*i, limit, i): # Mark factors non-prime
a[n] = False
if __name__ == '__main__':
results = []
digits = '123456789'
primes = sieve_of_eratosthenes(MAX_NUM)
for prime in primes:
if ''.join(sorted(str(prime))) == digits[:len(str(prime))]:
results.append(prime)
print(results)