programming-examples/python/Algorithms/permutations.py
2019-11-15 12:59:38 +01:00

18 lines
325 B
Python

def generate_permutations(p, depth):
n = len(p)
if depth == n:
yield p
for i in range(n):
if p[i] == 0:
p[i] = depth
yield from generate_permutations(p, depth + 1)
p[i] = 0
def test():
for p in generate_permutations([0] * 3, 1):
print(p)
test()