adventofcode2022/day08/sol.py

43 lines
913 B
Python
Raw Normal View History

2022-12-08 05:33:14 +00:00
data = []
for line in open("input"):
data.append(list(map(int, line.strip())))
visible = [[0]*len(x) for x in data]
for i in range(len(data)):
h = -1
for j in range(len(data[i])):
if data[i][j] > h:
visible[i][j] = 1
h = data[i][j]
if h == 9:
break
h = -1
for j in reversed(range(len(data[i]))):
if data[i][j] > h:
visible[i][j] = 1
h = data[i][j]
if h == 9:
break
for j in range(len(data[0])):
h = -1
for i in range(len(data)):
if data[i][j] > h:
visible[i][j] = 1
h = data[i][j]
if h == 9:
break
h = -1
for i in reversed(range(len(data))):
if data[i][j] > h:
visible[i][j] = 1
h = data[i][j]
if h == 9:
break
#print(visible)
print(sum(sum(x) for x in visible))