Permutations: Difference between revisions

m
Line 3,006:
(2, 1, 0)</lang>
 
=== Iterative implementation ===
 
Given a permutation, one can easily compute the ''next'' permutation in some ordreorder, for example lexicographic order, here. Then to get all permutations, it's enough to start from [0, 1, ... n-1], and store the next permutation until [n-1, n-2, ... 0], which is the last in lexicographic order.
 
<lang python>def nextperm(a):
Anonymous user