-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path#41.py
More file actions
29 lines (22 loc) · 662 Bytes
/
#41.py
File metadata and controls
29 lines (22 loc) · 662 Bytes
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
from math import sqrt
from itertools import count, islice
def check_pandigital(string, s=9):
string = str(string)
return len(string) == s and not '1234567890'[:s].strip(string)
def isPrime(n):
if n < 2 or n % 2 == 0:
return False
for i in islice(count(3, 2), int(sqrt(n)-1)//2):
if n % i == 0:
return False
return True
def PrimePandigital():
"""The pandigital for n=9,8,6,5 is always a multiple of 3.
Returns
-------
Maximum pandigital prime.
"""
for x in xrange(7654321, 7123456+1, -2):
if isPrime(x) and check_pandigital(x, 7):
return x
print PrimePandigital()