-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheul41.py
60 lines (33 loc) · 1.25 KB
/
eul41.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#Pandigital prime
#We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly once. For example, 2143 is a 4-digit pandigital and is also prime.
#What is the largest n-digit pandigital prime that exists?
#STRATEGY:
#find all pandigital numbers
#order them from largest to smallest
#start testing if prime, stop once a prime is found
import number_permutations
#number_permutations.main(x) finds all the permutations of the digits of x
import check_prime
#check_prime.main(x) checks if a number is prime and returns 1 if it is (and 0 if it isn't)
def main(x):
pandigitals = number_permutations.main(x)
#gets all permutations of entered digits
pandigitals = sorted(pandigitals)
#sorts the pandigital permutations (smallest to largest)
pandigitals = pandigitals [::-1]
#reverses the order so the pandigitals are largest to smallest
prime = 0
#will store eventual answer
index = 0
#placeholder index
while prime == 0:
#continues until a prime is found
print(index)
if check_prime.main( pandigitals[ index ] ) == 1:
#checks if number is prime
prime = pandigitals[ index ]
#stores prime if found
else:
#if number checked is not prime, increments index for search
index += 1
return prime