Lexicographic permutations
First read the problem description.
def next_permutation(a):
= len(a) - 1
i while a[i-1] >= a[i]:
-= 1
i
= len(a)
j while a[j-1] <= a[i-1]:
-= 1
j
-1], a[j-1] = a[j-1], a[i-1]
a[i
+= 1
i = len(a)
j while i < j:
-1], a[j-1] = a[j-1], a[i-1]
a[i+= 1
i -= 1
j
= list(range(0, 9+1))
digits for _ in range(1_000_000-1):
next_permutation(digits)
Source code of the solution(s):