35 lines
836 B
Python
35 lines
836 B
Python
#!/usr/bin/env python
|
|
"""
|
|
Created on 29 Jun 2021
|
|
|
|
@author: David Doblas Jiménez
|
|
@email: daviddoji@pm.me
|
|
|
|
Solution for problem 041 of Project Euler
|
|
https://projecteuler.net/problem=41
|
|
"""
|
|
|
|
from project_euler_python.utils import is_prime, timeit
|
|
|
|
|
|
@timeit("Problem 041")
|
|
def compute():
|
|
"""
|
|
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?
|
|
"""
|
|
|
|
pandigital = [str(number) for number in range(1, 10)]
|
|
|
|
for ans in range(7654321, 1, -1):
|
|
if sorted(str(ans)) == pandigital[: len(str(ans))]:
|
|
if is_prime(ans):
|
|
return ans
|
|
|
|
|
|
if __name__ == "__main__":
|
|
print(f"Result for Problem 041: {compute()}")
|