blob: e183bf29bc2710a7282f7e38184521dd6518fa07 (
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
|
import sys
def isVisible(lines, row, col):
scenic = 1
score = [1,2,3,4]
score[0] = [x[col] < lines[row][col] for x in lines[:row][::-1]]
score[1] = [x[col] < lines[row][col] for x in lines[row+1:]]
score[2] = [x < lines[row][col] for x in lines[row][:col][::-1]]
score[3] = [x < lines[row][col] for x in lines[row][col+1:]]
for a in score:
# print(a)
dist = 0
if (len(a) == 0):
dist = 0
elif (all(a)):
dist = len(a)
else:
dist = a.index(False) + 1
# print(dist)
scenic *= dist
print(row, col, "|", 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)
|