Refactor without building the whole list

This commit is contained in:
2026-04-11 15:35:30 +02:00
parent 8c3da33225
commit a036c30fc4

View File

@@ -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