-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path12_3.py
79 lines (72 loc) · 1.47 KB
/
12_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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
data = []
with open('num3.txt', 'r') as f:
my_data = f.readlines()
for line in my_data:
line_data = list(line)[:-1]
data.append(line_data)
hight = data.__len__()
width = data[0].__len__()
print(hight, width)
# right 3, down 1
tree_num1 = 0
for i in range(hight):
if i == 0:
j = 0
elif i <= (width / 3):
j = i * 3
else:
j = (i * 3) % width
if data[i][j] == '#':
tree_num1 += 1
print(tree_num1)
# right 1, down 1
tree_num2 = 0
for i in range(hight):
if i == 0:
j = 0
# elif i <= (width/1):
# j = i * 1
else:
j = (i * 1) % width
if data[i][j] == '#':
tree_num2 += 1
print(tree_num2)
# right 5, down 1
tree_num3 = 0
for i in range(hight):
if i == 0:
j = 0
elif i <= (width / 5):
j = i * 5
else:
j = (i * 5) % width
if data[i][j] == '#':
tree_num3 += 1
print(tree_num3)
# right 7, down 1
tree_num4 = 0
for i in range(hight):
if i == 0:
j = 0
elif i <= (width / 7):
j = i * 7
else:
j = (i * 7) % width
if data[i][j] == '#':
tree_num4 += 1
print(tree_num4)
# right 1, down 2
tree_num5 = 0
for i in range(hight):
if i % 2 == 1:
continue
if i == 0:
j = 0
# elif i <= (width/5):
# j = i * 5
else:
j = (i * 1) % width
if data[i][j] == '#':
tree_num5 += 1
print(tree_num5)
print(tree_num1*tree_num2*tree_num3*tree_num4*tree_num5)