Commit graph

1 commit

Author SHA1 Message Date
657fe956f9 Solve 2022 day 9 pt 1-2
Pt 1 was just head and tail. For pt 2 I rewrote the
code to instead build the rope (snake) from head to
tail by always moving the head first and traverse
the body of the snake.

Yes, I think of it as a body of a snake - not knots
on a rope. Child hood memories are to damn colorful
:)

For reference, this is my visually debugging code:

def dbg(seen, snake):
    print(snake)
    for r in range(-4, 1):
        print("".join([v(r, c, snake) for c in range(0, 7)]))
    print("")

def v(r, c, snake):
    if (r,c) == snake[0]:
        return "H"
    for i, n in enumerate(snake[1:-1], start=1):
        if (r,c) == n:
            return str(i)
    if (r,c) == snake[-1]:
        return "T"
    if (r,c) == (0,0):
        return "s"
    return "."
2025-11-30 19:17:15 +01:00