Initial commit
This commit is contained in:
25
problem-41.py
Normal file
25
problem-41.py
Normal 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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user