-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday08.py
45 lines (37 loc) · 1.03 KB
/
day08.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
with open("inputs/day08.txt", "r") as f:
grid = [list(map(int, line.strip())) for line in f.readlines()]
vis_count = 4 * len(grid) - 4
max_score = 0
for x in range(1, len(grid) - 1):
for y in range(1, len(grid) - 1):
scenic = 1
vis = 0
for i in range(x + 1, len(grid)):
if grid[i][y] >= grid[x][y]:
break
else:
vis = 1
scenic *= i - x
for i in range(y + 1, len(grid)):
if grid[x][i] >= grid[x][y]:
break
else:
vis = 1
scenic *= i - y
for i in range(x - 1, -1, -1):
if grid[i][y] >= grid[x][y]:
break
else:
vis = 1
scenic *= x - i
for i in range(y - 1, -1, -1):
if grid[x][i] >= grid[x][y]:
break
else:
vis = 1
scenic *= y - i
if vis:
vis_count += 1
max_score = max(max_score, scenic)
print('Part1: ', vis_count)
print('Part2: ', max_score)