You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

18 lines
325 B
Python

5 years ago
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()