Adopted new convention from template
This commit is contained in:
parent
80bb7a94ed
commit
ca06cc5543
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python
|
||||||
"""
|
"""
|
||||||
Created on 29 Jun 2021
|
Created on 29 Jun 2021
|
||||||
|
|
||||||
@ -9,31 +9,32 @@ Solution for problem 41 of Project Euler
|
|||||||
https://projecteuler.net/problem=41
|
https://projecteuler.net/problem=41
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from utils import timeit, is_prime
|
from utils import is_prime, timeit
|
||||||
|
|
||||||
|
|
||||||
@timeit("Problem 41")
|
@timeit("Problem 41")
|
||||||
def compute():
|
def compute():
|
||||||
"""
|
"""
|
||||||
We shall say that an n-digit number is pandigital if it makes
|
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
|
use of all the digits 1 to n exactly once. For example, 2143 is
|
||||||
a 4-digit pandigital and is also prime.
|
a 4-digit pandigital and is also prime.
|
||||||
|
|
||||||
What is the largest n-digit pandigital prime that exists?
|
What is the largest n-digit pandigital prime that exists?
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def is_pandigital(number):
|
def is_pandigital(number):
|
||||||
number = sorted(str(number))
|
number = sorted(str(number))
|
||||||
check = [str(i) for i in range(1, len(number)+1)]
|
check = [str(i) for i in range(1, len(number) + 1)]
|
||||||
if number == check:
|
if number == check:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
for ans in range(7654321, 1, -1):
|
for ans in range(7654321, 1, -1):
|
||||||
if is_pandigital(ans):
|
if is_pandigital(ans):
|
||||||
if is_prime(ans):
|
if is_prime(ans):
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
|
|
||||||
print(f"Result for Problem 41: {compute()}")
|
if __name__ == "__main__":
|
||||||
|
print(f"Result for Problem 41 is {compute()}")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user