diff --git a/src/Python/Problem038.py b/src/Python/Problem038.py new file mode 100644 index 0000000..bb38c86 --- /dev/null +++ b/src/Python/Problem038.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python3 +""" +Created on 03 Jun 2021 + +@author: David Doblas Jiménez +@email: daviddoji@pm.me + +Solution for problem 38 of Project Euler +https://projecteuler.net/problem=38 +""" + +from utils import timeit + + +@timeit("Problem 38") +def compute(): + """ + Take the number 192 and multiply it by each of 1, 2, and 3: + + 192 × 1 = 192 + 192 × 2 = 384 + 192 × 3 = 576 + + By concatenating each product we get the 1 to 9 pandigital, + 192384576. We will call 192384576 the concatenated product of + 192 and (1,2,3) + + The same can be achieved by starting with 9 and multiplying by + 1, 2, 3, 4, and 5, giving the pandigital, 918273645, which is + the concatenated product of 9 and (1,2,3,4,5). + + What is the largest 1 to 9 pandigital 9-digit number that can + be formed as the concatenated product of an integer with + (1,2, ... , n) where n > 1? + + """ + + results = [] + # Number must 4 digits (exactly) to be pandigital + # if n > 1 + for i in range(1, 10_000): + integer = 1 + number = "" + while len(number) < 9: + number += str(integer * i) + if sorted(number) == list('123456789'): + results.append(number) + + integer += 1 + + return max(results) + + +if __name__ == "__main__": + + print(f"Result for Problem 38: {compute()}")