Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ```
- # lets count the permutations of [1..n]
- def iterate(n):
- co = 0
- x = [0]
- while len(x) > 0:
- c = len(x) - 1
- x[c] += 1
- if x[c] <= n:
- if all(x[i] != x[c] for i in range(c)):
- if c < n - 1:
- x.append(0)
- else:
- co += 1
- # print(co, x)
- else:
- x.pop()
- return co
- print(iterate(5))
- ```
Advertisement
Add Comment
Please, Sign In to add comment