Unable to load image

Advent of Code 2022: Day 8

Post solutions here :marseysad: :marseyill:

25
Jump in the discussion.

No email address required.

Not very pretty, but I was able to write it quickly

import numpy as np
f = open('AOC2022Day8.txt')
lines = f.read().strip().split('\n')
grid = [[int(i) for i in line] for line in lines]
total = 0
best = 0
for i in range(len(grid)):
    for j in range(len(grid[0])):
        height = grid[i][j]
        ci,cj = i-1,j
        left = True
        dleft = 0
        dright = 0
        dup = 0
        ddown = 0
        right = True
        down = True
        up = True
        while ci >= 0:
            if grid[ci][cj] >= height:
                left = False
                dleft += 1
                break
            ci -= 1
            dleft += 1
        ci,cj = i,j-1
        while cj >= 0:
            
            if grid[ci][cj] >= height:
                up = False
                dup += 1
                break
            cj -= 1
            dup += 1
        ci,cj = i+1,j
        while ci < len(grid):
            if grid[ci][cj] >= height:
                dright += 1
                right = False
                break
            ci += 1
            dright += 1
        ci,cj = i,j+1
        while cj < len(grid[0]):
            if grid[ci][cj] >= height:
                down = False
                ddown += 1
                break
            cj += 1
            ddown += 1
        sscor = dup*ddown*dright*dleft
        if sscor > best:
            best = sscor
        if (up or down) or (right or left):
            total += 1
print(total)
print(best)

I had to fix a couple of off-by-one errors, and thought it would hurt my score more than it did

Jump in the discussion.

No email address required.

If only you could put that energy into your relationships

Jump in the discussion.

No email address required.

Link copied to clipboard
Action successful!
Error, please refresh the page and try again.