-
Notifications
You must be signed in to change notification settings - Fork 0
/
day08_part1_visible_trees.py
63 lines (56 loc) · 1.94 KB
/
day08_part1_visible_trees.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
def main():
DATA = []
with open('data/day08_tree_map.data') as f:
COLS = None
for row in f:
trees = []
for tree in row:
try:
trees.append(int(tree))
except:
# newline char will fail so can just continue
continue
if not COLS:
COLS = len(trees)
DATA.append(trees)
ROWS = len(DATA)
max_scenic_score = 0
for row in range(ROWS):
for column in range(COLS):
if row == 3 and column == 2:
pass
tree = DATA[row][column]
up_visibility = 0
for vision_row in range(row - 1, -1, -1):
up_visibility += 1
visible_tree = DATA[vision_row][column]
if visible_tree >= tree:
break
down_visibility = 0
for vision_row in range(row + 1, ROWS, 1):
down_visibility += 1
visible_tree = DATA[vision_row][column]
if visible_tree >= tree:
break
left_visibility = 0
for vision_column in range(column - 1, -1, -1):
left_visibility += 1
visible_tree = DATA[row][vision_column]
if visible_tree >= tree:
break
right_visibility = 0
for vision_column in range(column + 1, COLS, 1):
right_visibility += 1
visible_tree = DATA[row][vision_column]
if visible_tree >= tree:
break
scenic_score = up_visibility * down_visibility * left_visibility * right_visibility
if scenic_score > max_scenic_score:
max_scenic_score = scenic_score
print(f"answer: {max_scenic_score}")
if __name__ == "__main__":
main()
# 1265003 too low
# 1667443
# problem pwcvj
# pwcvj - 292769