-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_1.py
35 lines (27 loc) · 809 Bytes
/
test_1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from backtracklib import Solver
# 8 queens problem: position 8 queens on a chessboard so that no one attacks another.
def basecase(parcial):
if len(parcial) == 8:
return True
return False
def calculate_posibles(parcial):
ret = []
for x in range(8):
for y in range(8):
is_in = False
for i in range(8):
if (x,i) in parcial or (i, y) in parcial or (x-i, y-i) in parcial or (x+i, y+i) in parcial:
is_in = True
if not is_in:
ret.append((x,y))
return ret
gen = Solver(calculate_posibles, basecase)
answer1 = gen.solutions[0] # implicit solve and access
answers = gen.solve(num_answers=1, threading=True) # explicit solve
def test_1():
assert basecase(answer1)
for answer in answers:
assert basecase(answer)
if __name__ == "__main__":
print(answers)
print(len(answers))