-
Notifications
You must be signed in to change notification settings - Fork 0
/
queenknight.py
38 lines (34 loc) · 947 Bytes
/
queenknight.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
def count(n):
lukumaara = 0
for i in range(1, n+1):
for j in range(1, n+1):
for x in range(1, n+1):
for y in range(1, n+1):
if collision(i, j , x , y):
lukumaara +=1
return lukumaara
def collision(i, j , x, y):
if x == i or y == j or abs(x-i) == abs(y-j):
return False
if (x, y) == (i + 2, j + 1):
return False
if (x, y) == (i + 2, j - 1):
return False
if (x, y) == (i - 2, j + 1):
return False
if (x, y) == (i -2, j - 1):
return False
if (x, y) == (i + 1, j + 2):
return False
if (x, y) == (i + 1, j - 2):
return False
if (x, y) == (i - 1, j + 2):
return False
if (x, y) == (i - 1, j - 2):
return False
return True
if __name__ == "__main__":
print(count(3)) # 0
print(count(4)) # 40
print(count(5)) # 184
print(count(150))