-
Notifications
You must be signed in to change notification settings - Fork 0
/
4-3.py
57 lines (50 loc) · 1.13 KB
/
4-3.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
location = input()
first = location[0]
locate = [0,0]
result = 8
if first == 'a':
locate[0] = 1
elif first == 'b':
locate[0] = 2
elif first == 'c':
locate[0] = 3
elif first == 'd':
locate[0] = 4
elif first == 'e':
locate[0] = 5
elif first == 'f':
locate[0] = 6
elif first =='g':
locate[0] = 7
else:
locate[0] = 8
locate[1] = int(location[1])
h = [-2,2]
v = [-1,1]
for i in range(2):
x,y = locate
if i==0:
for j in h:
for k in v:
x,y = locate
x = x + j
y = y + k
if x<1 or x>8 or y<1 or y>8:
result-=1
else:
for j in h:
for k in v:
x,y = locate
x = x + k
y = y + j
if x<1 or x>8 or y<1 or y>8:
result-=1
print(result)
total = 0
steps = [(-2,-1),(-2,1),(2,-1),(2,1),(-1,-2),(-1,2),(1,2),(1,-2)]
for step in steps:
next_row = locate[1] + step[0]
next_col = locate[0] + step[1]
if next_row>=1 and next_row<=8 and next_col>=1 and next_col<=8:
total +=1
print(total)