summaryrefslogtreecommitdiff
path: root/2022/day08/main2.py
diff options
context:
space:
mode:
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: