Refactor without building the whole list
This commit is contained in:
@@ -9,7 +9,7 @@ Solution for problem 024 of Project Euler
|
|||||||
https://projecteuler.net/problem=24
|
https://projecteuler.net/problem=24
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from itertools import permutations
|
from itertools import islice, permutations
|
||||||
|
|
||||||
from project_euler_python.utils import timeit
|
from project_euler_python.utils import timeit
|
||||||
|
|
||||||
@@ -28,9 +28,10 @@ def compute():
|
|||||||
0, 1, 2, 3, 4, 5, 6, 7, 8 and 9?
|
0, 1, 2, 3, 4, 5, 6, 7, 8 and 9?
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
limit = 1_000_000
|
||||||
digits = list(range(10))
|
digits = list(range(10))
|
||||||
_permutations = list(permutations(digits))
|
millionth_permutation = next(islice(permutations(digits), limit - 1, limit))
|
||||||
ans = "".join(str(digit) for digit in _permutations[999_999])
|
ans = "".join(str(digit) for digit in millionth_permutation)
|
||||||
|
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user