From 675c03ef94946986e03dc5d221843339363e8e44 Mon Sep 17 00:00:00 2001 From: daviddoji Date: Sat, 11 Sep 2021 19:44:26 +0200 Subject: [PATCH] Solution to problem 41 --- src/Python/Problem041.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/Python/Problem041.py diff --git a/src/Python/Problem041.py b/src/Python/Problem041.py new file mode 100644 index 0000000..e205291 --- /dev/null +++ b/src/Python/Problem041.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 +""" +Created on 29 Jun 2021 + +@author: David Doblas Jiménez +@email: daviddoji@pm.me + +Solution for problem 41 of Project Euler +https://projecteuler.net/problem=41 +""" + +from utils import timeit, is_prime + + +@timeit("Problem 41") +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? + """ + def is_pandigital(number): + number = sorted(str(number)) + check = [str(i) for i in range(1, len(number)+1)] + if number == check: + return True + return False + + + for ans in range(7654321, 1, -1): + if is_pandigital(ans): + if is_prime(ans): + return ans + +if __name__ == "__main__": + + print(f"Result for Problem 41: {compute()}") \ No newline at end of file