summaryrefslogtreecommitdiff
path: root/2022/day08/main2.py
blob: 9db38794229eb1675e0ead0d224ff8e1d4e76d1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import sys

def isVisible(lines, row, col):
    scenic = 1

    # up
    score1 = 0
    for x in lines[:row][::-1]:
        score1 += 1
        if ( x[col] >= lines[row][col]):
            break
    scenic *= score1

    # left
    score3 = 0
    for x in lines[row][:col-1][::-1]:
        score3 += 1
        if ( x >= lines[row][col]):
            break
    scenic *= score3

    # right
    score4 = 0
    for x in lines[row][col+1:]:
        score4 += 1
        if ( x >= lines[row][col]):
            break
    scenic *= score4

    # 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:
    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)