Day 08
This commit is contained in:
43
day08/part1.py
Normal file
43
day08/part1.py
Normal 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))
|
||||
|
||||
Reference in New Issue
Block a user