-
Notifications
You must be signed in to change notification settings - Fork 0
/
16diagonals.py
58 lines (55 loc) · 1.38 KB
/
16diagonals.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
g = [[-1]*5 for i in range(5)]
def poss(c, i, j):
if c == '\\':
if i>0 and g[i-1][j] == '/':
return False
if j>0 and g[i][j-1] == '/':
return False
if i > 0 and j > 0 and g[i-1][j-1] == '\\':
return False
if i < 4 and j < 4 and g[i+1][j+1] == '\\':
return False
else:
if i>0 and g[i-1][j] == '\\':
return False
if j>0 and g[i][j-1] == '\\':
return False
if i > 0 and j > 0 and g[i-1][j-1] == '/':
return False
if i < 4 and j < 4 and g[i+1][j+1] == '/':
return False
return True
mx = 0
def printG():
for row in g:
print(row)
def kill(i, j, sol, size):
global mx, g
# mx = max(mx, len(sol))
if len(sol) == size:
print(g)
return
if i >= 5 or j >= 5 or (i, j) in sol:
return
print (i, j)
# printG()
c = g[i][j]
if poss('/', i, j):
sol.append((i, j))
g[i][j] = '/'
kill(i+1, j, sol, size)
kill(i, j+1, sol, size)
# g[i][j] = c
sol.pop(-1)
if poss('\\', i, j):
sol.append((i, j))
g[i][j] = '\\'
kill(i+1, j, sol, size)
kill(i, j+1, sol, size)
# g[i][j] = c
sol.pop(-1)
kill(i+1, j, sol, size)
kill(i, j+1, sol, size)
g[i][j] = c
kill(0, 0, [], 16)
# print(mx)