Data update

This commit is contained in:
Ingy dot Net 2024-04-19 16:56:29 -07:00
parent 0df55f9f24
commit aec8ed51b6
1045 changed files with 18889 additions and 2777 deletions

View file

@ -1,4 +1,4 @@
def queens(n, i, a, b, c):
def queens(n: int, i: int, a: list, b: list, c: list):
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:
@ -6,5 +6,6 @@ def queens(n, i, a, b, c):
else:
yield a
for solution in queens(8, 0, [], [], []):
print(solution)

View file

@ -1,10 +1,14 @@
def queens(x, i, a, b, c):
if a: # a is not empty
def queens(i: int, a: set):
if a: # set a is not empty
for j in a:
if i + j not in b and i - j not in c:
yield from queens(x + [j], i + 1, a - {j}, b | {i + j}, c | {i - j})
b.add(i + j); c.add(i - j); x.append(j)
yield from queens(i + 1, a - {j})
b.remove(i + j); c.remove(i - j); x.pop()
else:
yield x
for solution in queens([], 0, set(range(8)), set(), set()):
b = set(); c = set(); x = []
for solution in queens(0, set(range(8))):
print(solution)