54 lines
1.2 KiB
Python
Executable file
54 lines
1.2 KiB
Python
Executable file
#!/bin/python3
|
|
|
|
forest = []
|
|
|
|
with open('day8.txt', 'r') as f:
|
|
for line in f:
|
|
forest.append(list(map(int, list(line.strip()))))
|
|
|
|
height = len(forest)
|
|
width = len(forest[0])
|
|
|
|
heighest = -1
|
|
heighest_x = -1
|
|
heighest_y = -1
|
|
|
|
for y in range(height):
|
|
for x in range(width):
|
|
h = forest[x][y]
|
|
tree_count = 1
|
|
|
|
tree_count_cur = 0
|
|
for cur_x in range(x+1, width):
|
|
tree_count_cur += 1
|
|
if forest[cur_x][y] >= h:
|
|
break
|
|
tree_count *= tree_count_cur
|
|
|
|
tree_count_cur = 0
|
|
for cur_x in range(x-1, -1, -1):
|
|
tree_count_cur += 1
|
|
if forest[cur_x][y] >= h:
|
|
break
|
|
tree_count *= tree_count_cur
|
|
|
|
tree_count_cur = 0
|
|
for cur_y in range(y+1, height):
|
|
tree_count_cur += 1
|
|
if forest[x][cur_y] >= h:
|
|
break
|
|
tree_count *= tree_count_cur
|
|
|
|
tree_count_cur = 0
|
|
for cur_y in range(y-1, -1, -1):
|
|
tree_count_cur += 1
|
|
if forest[x][cur_y] >= h:
|
|
break
|
|
tree_count *= tree_count_cur
|
|
|
|
if tree_count > heighest:
|
|
heighest = tree_count
|
|
heighest_x = x
|
|
heighest_y = y
|
|
|
|
print(x, y, heighest)
|