summaryrefslogtreecommitdiff
path: root/2022/day08/main2.py
diff options
context:
space:
mode:
authorOrangerot <purple@orangerot.dev>2022-12-17 01:58:22 +0100
committerOrangerot <purple@orangerot.dev>2022-12-17 01:58:22 +0100
commit4a894a7b95382a92303bf12191f0e1d1d6d72063 (patch)
treecab9d4136bb3bd8b2af67d430c34ddd5ca16db30 /2022/day08/main2.py
parent6596b48113ced669b206d2e1f1e8ba6edcba88a2 (diff)
finished day 8
Diffstat (limited to '2022/day08/main2.py')
-rw-r--r--2022/day08/main2.py34
1 files changed, 20 insertions, 14 deletions
diff --git a/2022/day08/main2.py b/2022/day08/main2.py
index a2a7df2..9db3879 100644
--- a/2022/day08/main2.py
+++ b/2022/day08/main2.py
@@ -2,35 +2,41 @@ import sys
def isVisible(lines, row, col):
scenic = 1
+
+ # up
score1 = 0
- for x in lines[:row:-1]:
- if ( x[col] >= lines[row][col]):
- break
+ for x in lines[:row][::-1]:
score1 += 1
- scenic *= score1
-
- score2 = 0
- for x in lines[row+1:]:
if ( x[col] >= lines[row][col]):
break
- score2 += 1
- scenic *= score2
+ scenic *= score1
+ # left
score3 = 0
- for x in lines[row][:col:-1]:
+ for x in lines[row][:col-1][::-1]:
+ score3 += 1
if ( x >= lines[row][col]):
break
- score3 += 1
scenic *= score3
+ # right
score4 = 0
- for x in lines[row][col:]:
+ for x in lines[row][col+1:]:
+ score4 += 1
if ( x >= lines[row][col]):
break
- score4 += 1
scenic *= score4
- print(row, col, score1, score2, score3, score4, scenic)
+ # down
+ score2 = 0
+ for x in lines[row:]:
+ score2 += 1
+ if ( x[col] >= lines[row][col]):
+ break
+ scenic *= score2
+
+
+ print(row, col, "|", score1, score2, score3, score4, "|", scenic)
return scenic
with open(sys.argv[1], "r") as file: