diff options
Diffstat (limited to '2022/day08/main2.py')
-rw-r--r-- | 2022/day08/main2.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/2022/day08/main2.py b/2022/day08/main2.py new file mode 100644 index 0000000..a2a7df2 --- /dev/null +++ b/2022/day08/main2.py @@ -0,0 +1,49 @@ +import sys + +def isVisible(lines, row, col): + scenic = 1 + score1 = 0 + for x in lines[:row:-1]: + if ( x[col] >= lines[row][col]): + break + score1 += 1 + scenic *= score1 + + score2 = 0 + for x in lines[row+1:]: + if ( x[col] >= lines[row][col]): + break + score2 += 1 + scenic *= score2 + + score3 = 0 + for x in lines[row][:col:-1]: + if ( x >= lines[row][col]): + break + score3 += 1 + scenic *= score3 + + score4 = 0 + for x in lines[row][col:]: + if ( x >= lines[row][col]): + break + score4 += 1 + scenic *= score4 + + print(row, col, score1, score2, score3, score4, 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) |