advent-of-code/2022/day08/main.py
2022-12-17 01:16:18 +01:00

40 lines
999 B
Python

import sys
def isVisible(lines, row, col):
if ( row == 0 or col == 0 or row == len(lines)-1 or col == len(lines[0])-1):
return True
if all(x[col] < lines[row][col] for x in lines[:row]):
return True
if all(x[col] < lines[row][col] for x in lines[row+1:]):
return True
if all(x < lines[row][col] for x in lines[row][:col]):
return True
if all(x < lines[row][col] for x in lines[row][col+1:]):
return True
return False
with open(sys.argv[1], "r") as file:
lines = file.readlines()
for a in range(len(lines)):
lines[a] = lines[a].rstrip()
# a = a.rstrip()
visible=0
for row in range(len(lines)):
for col in range(len(lines[0])):
# print(lines[row][col], end="")
yes = isVisible(lines, row, col)
visible += yes
if yes:
print("1", end="")
else:
print("_", end="")
print()
print(visible)