A permutation is a permutation of things. For example, 3124 is a permutation of numbers 1, 2, 3, 4. All permutations are lexicographically arranged in large or small numbers. Called order. If you arrange the permutations of 0, 1 and 2 in lexicographic order
012 021 102 120 201 210 become.
What is the 1 millionth when lexicographically arranging permutations consisting of 0,1,2,3,4,5,6,7,8,9? http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%2024
Will be added later (= not done).
import math
def main():
target = 10**6
target -=1
ans = ''
ls = range(10)
for i in range(9,-1,-1):
n = ls.pop(target // math.factorial(i))
target %= math.factorial(i)
ans += str(n)
print ans
main()
Recommended Posts