From 4a894a7b95382a92303bf12191f0e1d1d6d72063 Mon Sep 17 00:00:00 2001 From: Orangerot Date: Sat, 17 Dec 2022 01:58:22 +0100 Subject: finished day 8 --- 2022/day08/main2.py | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to '2022/day08/main2.py') 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: -- cgit v1.2.3