parent
29ddbf602b
commit
e2bf6fc1fa
1 changed files with 34 additions and 12 deletions
@ -1,27 +1,49 @@ |
|||||||
matrix = [[int(i) for i in j] for j in open("input2.txt", 'r').read().splitlines()] |
matrix = [[int(i) for i in j] for j in open("input.txt", 'r').read().splitlines()] |
||||||
visible = set() |
visible = set() |
||||||
|
highScore = 0 |
||||||
|
highScoreCoord = () |
||||||
|
|
||||||
def walk(line): |
def walk(line): |
||||||
length = len(line) |
vis = [0] |
||||||
vis = [0, length-1] |
|
||||||
tallest = line[0] |
tallest = line[0] |
||||||
tallestInv = line[-1] |
for i in range(1, len(line)): |
||||||
for i in range(1, length): |
|
||||||
if line[i] > tallest: |
if line[i] > tallest: |
||||||
vis.append(i) |
vis.append(i) |
||||||
tallest = line[i] |
tallest = line[i] |
||||||
if line[length-i] > tallestInv: |
|
||||||
vis.append(length-i) |
|
||||||
tallestInv = line[-i] |
|
||||||
print(vis) |
|
||||||
return vis |
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 i in range(len(matrix)): |
||||||
for coord in walk(matrix[i]): |
for coord in walk(matrix[i]): |
||||||
visible.add((i, coord)) |
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])): |
for i in range(len(matrix[0])): |
||||||
for coord in walk([matrix[j][i] for j 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)) |
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(visible) |
|
||||||
print(len(visible)) |
print(len(visible)) |
||||||
|
print(highScore) |
Loading…
Reference in new issue