Passed
Push — main ( 4fc6d1...8ecbea )
by Yohann
58s
created

main.count_visible()   A

Complexity

Conditions 1

Size

Total Lines 5
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
import pathlib
2
3
BOARD_SIZE = 99
4
5
6
def is_visible(board, x, y):
7
    return any(
8
        board[y][x] > max(trees)
9
        for trees in (
10
            board[y][:x],
11
            board[y][x + 1:],
12
            tuple(line[x] for line in board[:y]),
13
            tuple(line[x] for line in board[y + 1:])
14
        )
15
    )
16
17
18
def count_visible(board):
19
    return sum(
20
        is_visible(board, x, y)
21
        for x in range(1, BOARD_SIZE - 1) for y in range(1, BOARD_SIZE - 1)
22
    ) + (BOARD_SIZE - 1) * 4
23
24
25
def main():
26
    content = pathlib.Path('./input.txt').read_text()
27
    board = [line for line in content.splitlines()]
28
29
    print('Part 1:', count_visible(board))
30
31
32
if __name__ == '__main__':
33
    main()
34