Unable to load image

Advent of Code 2022: Day 8

Post solutions here :marseysad: :marseyill:

25
Jump in the discussion.

No email address required.

Anyone come up with an algorithm for part 2? For part 1, I created a map of the maximum value from each direction at any given point, which reduced the iterations to 4x the total number of trees, but for part 2 I just brute forced it by looking from every single tree. It would be interesting to see if there was, for example, some way of determining the left viewing distance during a single pass through a line from left to right.

Jump in the discussion.

No email address required.

    k = []
    s = []
    init = None
    for x, y in zip(xs, ys):
        if init is None:
            init = (x,y)
        while k and k[-1][0] < r[y][x]:
            k.pop()
        lx, ly = k[-1][1] if k else init
        s.append(sum(map(abs, [lx-x, ly-y])))
        k.append((r[y][x], (x,y)))
Jump in the discussion.

No email address required.

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