N-queens problem: Difference between revisions

m
m (→‎Python: Niklaus Wirth algorithm: The explicit copying of the set a is made implicit again.)
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)
c.add(i - j)
x.append(j)
yield from queen(i + 1, a - {j})
b.remove(i + j) ; c.remove(i - j) ; x.pop()
c.remove(i - j)
x.pop()
else:
yield x
 
b = set() ; c = set() ; x = []
c = set()
x = []
yield from queen(0, set(range(n)))
 
305

edits