Data update
This commit is contained in:
parent
0df55f9f24
commit
aec8ed51b6
1045 changed files with 18889 additions and 2777 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue