summaryrefslogtreecommitdiff
path: root/2022/08/a.py
blob: f7625548713bb9434949fdea06c74c70e4936af2 (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
def is_visible(i, j):
    this = grid[i][j]
    surround = [
        [grid[i2][j] for i2 in range(i)],
        [grid[i][j2] for j2 in range(j)],
        [grid[i2][j] for i2 in range(i+1, len(grid))],
        [grid[i][j2] for j2 in range(j+1, len(grid[0]))],
    ]
    return any([all([s < this for s in sur]) for sur in surround])

def view(i, j):
    score = 1
    this = grid[i][j]
    surround = [
        [grid[i2][j] for i2 in range(i-1, -1, -1)],
        [grid[i][j2] for j2 in range(j-1, -1, -1)],
        [grid[i2][j] for i2 in range(i+1, len(grid))],
        [grid[i][j2] for j2 in range(j+1, len(grid[0]))],
    ]
    for sur in surround:
        surlen = len(sur)
        i = 0
        while i < surlen and sur[i] < this:
            i += 1
        if i < surlen and sur[i] >= this:
            i += 1
        score *= i
    return score
    

#with open("example") as f:
with open("input") as f:
    grid = [line.strip() for line in f.readlines()]
width, height = len(grid[0]), len(grid)
edge_visible = (width + height-2) * 2 
highest = 0
for i in range(1, height-1):
    for j in range(1, width-1):
        score = view(i, j)
        if score > highest:
            highest = score
print(highest)