diff options
author | Orangerot <purple@orangerot.dev> | 2022-12-17 01:58:22 +0100 |
---|---|---|
committer | Orangerot <purple@orangerot.dev> | 2022-12-17 01:58:22 +0100 |
commit | 4a894a7b95382a92303bf12191f0e1d1d6d72063 (patch) | |
tree | cab9d4136bb3bd8b2af67d430c34ddd5ca16db30 /2022/day08/main3.py | |
parent | 6596b48113ced669b206d2e1f1e8ba6edcba88a2 (diff) |
finished day 8
Diffstat (limited to '2022/day08/main3.py')
-rw-r--r-- | 2022/day08/main3.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/2022/day08/main3.py b/2022/day08/main3.py new file mode 100644 index 0000000..e183bf2 --- /dev/null +++ b/2022/day08/main3.py @@ -0,0 +1,40 @@ +import sys + +def isVisible(lines, row, col): + scenic = 1 + score = [1,2,3,4] + score[0] = [x[col] < lines[row][col] for x in lines[:row][::-1]] + score[1] = [x[col] < lines[row][col] for x in lines[row+1:]] + score[2] = [x < lines[row][col] for x in lines[row][:col][::-1]] + score[3] = [x < lines[row][col] for x in lines[row][col+1:]] + + + for a in score: + # print(a) + dist = 0 + if (len(a) == 0): + dist = 0 + elif (all(a)): + dist = len(a) + else: + dist = a.index(False) + 1 + # print(dist) + scenic *= dist + + print(row, col, "|", scenic) + return scenic + +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() + + best=0 + for row in range(len(lines)): + for col in range(len(lines[0])): + # print(lines[row][col], end="") + yes = isVisible(lines, row, col) + best = max(best, yes) + + print(best) |