RosettaCodeData/Task/N-queens-problem/Python/n-queens-problem-5.py

12 lines
323 B
Python

def solve(n, i, a, b, c):
if i < n:
for j in range(n):
if j not in a and i+j not in b and i-j not in c:
for solution in solve(n, i+1, a+[j], b+[i+j], c+[i-j]):
yield solution
else:
yield a
for solution in solve(8, 0, [], [], []):
print(solution)