This commit is contained in:
Sebastian Seedorf
2022-12-09 09:26:32 +01:00
parent 1bd0017a32
commit 60dc09699f
4 changed files with 171 additions and 0 deletions

43
day08/part1.py Normal file
View File

@@ -0,0 +1,43 @@
#!/usr/bin/env python3
import numpy as np
forest = np.array([np.array(list(map(int, x.strip()))) for x in open("input.txt")])
print("x", forest)
visible = np.full_like(forest, False, dtype=bool)
# top
height = np.repeat(-1, len(forest[0]))
for i in range(0, len(forest)):
visible[i] = visible[i] | (forest[i] > height)
height = np.max([height, forest[i]], axis=0)
if np.all(height == 9):
break
# bottom
height = np.repeat(-1, len(forest[0]))
for i in range(len(forest)-1, -1, -1):
visible[i] = visible[i] | (forest[i] > height)
height = np.max([height, forest[i]], axis=0)
if np.all(height == 9):
break
# left
height = np.repeat(-1, len(forest))
for i in range(0, len(forest[0])):
visible[:, i] = visible[:, i] | (forest[:, i] > height)
height = np.max([height, forest[:, i]], axis=0)
if np.all(height == 9):
break
# left
height = np.repeat(-1, len(forest))
for i in range(len(forest[0])-1, -1, -1):
visible[:, i] = visible[:, i] | (forest[:, i] > height)
height = np.max([height, forest[:, i]], axis=0)
if np.all(height == 9):
break
print(np.count_nonzero(visible))