N-queens problem: Difference between revisions
m
→Python: Niklaus Wirth algorithm: Code made compact
m (→Python: Niklaus Wirth algorithm: The explicit copying of the set a is made implicit again.) |
m (→Python: Niklaus Wirth algorithm: Code made compact) |
||
Line 12,848:
for j in a:
if i + j not in b and i - j not in c:
b.add(i + j) ; c.add(i - j) ; x.append(j)
yield from queen(i + 1, a - {j})
b.remove(i + j) ; c.remove(i - j) ; x.pop()
else:
yield x
b = set() ; c = set() ; x = []
yield from queen(0, set(range(n)))
|