28 lines
685 B
Python
Executable File
28 lines
685 B
Python
Executable File
#!/usr/bin/env python
|
|
from common import parse
|
|
|
|
|
|
def is_visible(forest: list[list[int]], x: int, y: int) -> bool:
|
|
height = forest[y][x]
|
|
west = forest[y][0:x]
|
|
east = forest[y][x + 1 :]
|
|
north = [forest[i][x] for i in range(y)]
|
|
south = [forest[i][x] for i in range(y + 1, len(forest))]
|
|
return any(map(lambda x: x == [] or max(x) < height, (west, east, north, south)))
|
|
|
|
|
|
def solve(input: list[list[int]]) -> int:
|
|
count = 0
|
|
for y, line in enumerate(input):
|
|
for x, tree in enumerate(line):
|
|
count += 1 if is_visible(input, x, y) else 0
|
|
return count
|
|
|
|
|
|
def main():
|
|
print(solve(parse("input")))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|