You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.4 KiB
49 lines
1.4 KiB
matrix = [[int(i) for i in j] for j in open("input.txt", 'r').read().splitlines()]
|
|
visible = set()
|
|
highScore = 0
|
|
highScoreCoord = ()
|
|
|
|
def walk(line):
|
|
vis = [0]
|
|
tallest = line[0]
|
|
for i in range(1, len(line)):
|
|
if line[i] > tallest:
|
|
vis.append(i)
|
|
tallest = line[i]
|
|
return vis
|
|
|
|
def findFirst(line, height):
|
|
for i in range(len(line)):
|
|
if line[i] >= height:
|
|
return i+1
|
|
return len(line)
|
|
|
|
for i in range(len(matrix)):
|
|
for coord in walk(matrix[i]):
|
|
visible.add((i, coord))
|
|
for coord in walk(matrix[i][::-1]):
|
|
visible.add((i, len(matrix) - (coord) - 1))
|
|
|
|
|
|
for i in range(len(matrix[0])):
|
|
col = [matrix[j][i] for j in range(len(matrix[0]))]
|
|
for coord in walk(col):
|
|
visible.add((coord, i))
|
|
for coord in walk(col[::-1]):
|
|
visible.add((len(matrix[0]) - (coord) - 1, i))
|
|
|
|
for i in range(len(matrix)):
|
|
for j in range(len(matrix[0])):
|
|
score = 0
|
|
left = findFirst(matrix[i][:j][::-1], matrix[i][j])
|
|
right = findFirst(matrix[i][j+1:], matrix[i][j])
|
|
col = [matrix[x][j] for x in range(len(matrix[0]))]
|
|
up = findFirst(col[:i][::-1], matrix[i][j])
|
|
down = findFirst(col[i+1:], matrix[i][j])
|
|
score = up*down*left*right
|
|
if score > highScore:
|
|
highScore = score
|
|
highScoreCoord = (i,j)
|
|
|
|
print(len(visible))
|
|
print(highScore) |