summaryrefslogtreecommitdiff
path: root/2022/day08/main.py
blob: 45ba1425dd50a01b2d023385a42f29c3a0727c15 (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
import sys

def isVisible(lines, row, col):
    if ( row == 0 or col == 0 or row == len(lines)-1 or col == len(lines[0])-1):
        return True

    if all(x[col] < lines[row][col] for x in lines[:row]):
        return True

    if all(x[col] < lines[row][col] for x in lines[row+1:]):
        return True

    if all(x < lines[row][col] for x in lines[row][:col]):
        return True

    if all(x < lines[row][col] for x in lines[row][col+1:]):
        return True

    return False

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()

    visible=0
    for row in range(len(lines)):
        for col in range(len(lines[0])):
            # print(lines[row][col], end="")
            yes = isVisible(lines, row, col)
            visible += yes
            if yes:
                print("1", end="")
            else:
                print("_", end="")
        print()

    print(visible)