diff options
Diffstat (limited to '2022/day08/main.py')
-rw-r--r-- | 2022/day08/main.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/2022/day08/main.py b/2022/day08/main.py new file mode 100644 index 0000000..45ba142 --- /dev/null +++ b/2022/day08/main.py @@ -0,0 +1,39 @@ +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) |