-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday8.py
41 lines (35 loc) · 1.09 KB
/
day8.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
data = open('input_day8.txt').readlines()
#print(data)
forest = [[int(x) for x in row.strip()] for row in data]
#print(forest[0])
forest2 = list(zip(*forest))
#print(forest2[0:2])
s = 0
for i in range(len(forest[0])):
for j in range(len(forest)):
tree = forest[i][j]
if all(x < tree for x in forest[i][0:j]) or \
all(x < tree for x in forest[i][j+1:]) or \
all(x < tree for x in forest2[j][0:i]) or \
all(x < tree for x in forest2[j][i+1:]):
s += 1
print(s)
s = 0
def view_length(tree, view):
view_length = 0
for v in view:
view_length += 1
if v >= tree:
break
return view_length
for i in range(len(forest[0])):
for j in range(len(forest)):
tree = forest[i][j]
s1 = view_length(tree, forest[i][0:j][::-1])
s2 = view_length(tree, forest[i][j+1:])
s3 = view_length(tree, forest2[j][0:i][::-1])
s4 = view_length(tree, forest2[j][i+1:])
score = s1 * s2 * s3 * s4
if score > s:
s = score
print(s)