# Determine all permutations of numbers 0, 1, ..., (n-1)
seq = range(5) # the current permutation, starting with 0, 1, ... (n-1)
cnt = 0 # counting (and numbering) the permutationsn
# perm(i) computes the permutations of seq [i:], with fixed prefix seq [0:i-1]
# should return seq in original state
def perm (i):
global cnt
if i==len(seq)-1:
print "sec=", seq
cnt = cnt+1
else:
for j in range (i, len(seq)):
seq[i], seq[j] = seq [j], seq[i]
perm (i+1)
seq[i], seq[j] = seq [j], seq[i]
print "seq = ", seq, "len =", len(seq)
perm (0)
print "cnt =", cnt