adventOfCode/challenges/2024/06-guardGallivant
2024-12-07 00:09:33 +00:00
..
main.py Update main.py 2024-12-07 00:09:33 +00:00
README.md Optimise the snot out of 2024.06 2024-12-07 00:07:02 +00:00
tests.json 2024.06 2024-12-06 16:36:41 +00:00

Day 6: Guard Gallivant

Part 2 is:

  • higher than 456
  • less than 1689

The first implementation of part 2 took 15 minutes to run.

  • Turning visited_sequence in trace into a set instead of a list cut this to 60 seconds
  • Starting immediately in front of the new obstacle when testing positions to put said new obstacle in cut this to 20 seconds
  • Removing a load of maps and type wranging to turn the fully generic gridutil.add (and counterparts) into a more limited but much faster function took this to ~16 seconds

Before:

def _coordmap(a: AnyCoordinate, b: AnyCoordinate, fn: Callable) -> AnyCoordinate:
    at = type(a)
    return at(*map(fn, zip(a, b)))

def add(a: AnyCoordinate, b: AnyCoordinate) -> AnyCoordinate:
    return _coordmap(a, b, lambda x: x[0] + x[1])

After:

def add(a: Coordinate, b: Coordinate) -> Coordinate:
    return Coordinate(a.x + b.x, a.y + b.y)