diff --git a/src/project_euler_python/problems_001_050/Problem024.py b/src/project_euler_python/problems_001_050/Problem024.py index 2645b9b..65e6de2 100644 --- a/src/project_euler_python/problems_001_050/Problem024.py +++ b/src/project_euler_python/problems_001_050/Problem024.py @@ -9,7 +9,7 @@ Solution for problem 024 of Project Euler https://projecteuler.net/problem=24 """ -from itertools import permutations +from itertools import islice, permutations from project_euler_python.utils import timeit @@ -28,9 +28,10 @@ def compute(): 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9? """ + limit = 1_000_000 digits = list(range(10)) - _permutations = list(permutations(digits)) - ans = "".join(str(digit) for digit in _permutations[999_999]) + millionth_permutation = next(islice(permutations(digits), limit - 1, limit)) + ans = "".join(str(digit) for digit in millionth_permutation) return ans