Euler 0024
The Problem:
What is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9?
Considerations and Approach:
Well, this is another problem that Python has a simple built in way...
Generating all of the permutations of the numbers 0-9 is not computationally an issue for itertools, we can then sort those permutations and grab out the millionth permutation and that's our answer.
The Code:
import itertools
#Sorry that the next few lines don't look pythonic, I adjusted them for comment clarity sake
#The line should actually just read sorted(itertools.permutations(list(range(10))))[999999]
#We sort
sorted(
#all the permutations
itertools.permutations(
#of the numbers 0-9
list(range(10))
)
#and then we grab out the millionth permutation
)[999999]
No comments to display
No comments to display