File tree Expand file tree Collapse file tree 1 file changed +6
-20
lines changed Expand file tree Collapse file tree 1 file changed +6
-20
lines changed Original file line number Diff line number Diff line change @@ -7,20 +7,13 @@ def first(data):
7
7
while r < len (data ):
8
8
c = 0
9
9
while c < len (data [r ]):
10
- if r == 0 or c == 0 or r == len (data ) - 1 or c == len (data [r ]) - 1 :
10
+ if r == 0 or c == 0 or r == len (data ) - 1 or c == len (data [r ]) - 1 or any ([
11
+ all (data [r ][i ] < data [r ][c ] for i in range (c )), # left
12
+ all (data [i ][c ] < data [r ][c ] for i in range (r )), # top
13
+ all (data [r ][i ] < data [r ][c ] for i in range (len (data [r ]) - 1 , c , - 1 )), # rigth
14
+ all (data [i ][c ] < data [r ][c ] for i in range (len (data ) - 1 , r , - 1 )) # down
15
+ ]):
11
16
visible_trees += 1
12
- else :
13
- visible = False
14
- if all (data [r ][i ] < data [r ][c ] for i in range (c )):
15
- visible = True
16
- elif all (data [i ][c ] < data [r ][c ] for i in range (r )):
17
- visible = True
18
- elif all (data [r ][i ] < data [r ][c ] for i in range (len (data [r ]) - 1 , c , - 1 )):
19
- visible = True
20
- elif all (data [i ][c ] < data [r ][c ] for i in range (len (data ) - 1 , r , - 1 )):
21
- visible = True
22
- if visible :
23
- visible_trees += 1
24
17
c += 1
25
18
r += 1
26
19
@@ -75,13 +68,6 @@ def second(data):
75
68
76
69
if __name__ == "__main__" :
77
70
content = get_input_content (__file__ )
78
- test_input = '''30373
79
- 25512
80
- 65332
81
- 33549
82
- 35390'''
83
- # if test_input:
84
- # content = test_input.split('\n')
85
71
86
72
grid = [list (line ) for line in content ]
87
73
You can’t perform that action at this time.
0 commit comments