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

12 lines
323 B
Python
Raw Permalink Normal View History

2019-09-12 10:33:56 -07:00
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
2015-11-18 06:14:39 +00:00
2019-09-12 10:33:56 -07:00
for solution in solve(8, 0, [], [], []):
print(solution)