diff options
author | Orangerot <purple@orangerot.dev> | 2022-12-17 01:16:18 +0100 |
---|---|---|
committer | Orangerot <purple@orangerot.dev> | 2022-12-17 01:16:18 +0100 |
commit | 6596b48113ced669b206d2e1f1e8ba6edcba88a2 (patch) | |
tree | 02c7d01783390862d989df6c91aff968e03dd415 /2022/day08/main.py |
adv2022 first 8 days
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) |