Advent of Code 2019 - Day 19

Note: This topic is to talk about Day 19 of the Advent of Code 2019.

There is a private leaderboard for elixirforum members. You can join it by following this link and entering the following code:

39276-eeb74f9a

Here is my solution.

It finishes in about 5 seconds. That’s fast enough for me, so I didn’t try any optimizations. There is a another puzzle that better needs my optimization efforts.

UPDATE: I realized that it is much faster to first test that the lower right corner of the ship fits. My optimized solution reduces the runtime to 0.8 seconds.

Today’s wasn’t bad at all (I gave up on yesterday’s).

The part 2 solution I came up with was easy to implement:

  • start with NW corner at known good location (0,0)
  • A) move S until NE corner is within beam
  • B) move E until SW corner is within beam
  • Repeat A & B until both SW and NE corners are within beam

I added some caching so we don’t have to run the Intcode computer as much, but that probably wasn’t necessary.

Day 19 Solution

Today was nice, and much simpler than the past few days!

Here’s my take. The core of the solution is in this function which returns data about pulls for each row. In this function I made a few assumptions about the beam shape which allowed me to reduce the running time to 2 seconds.

Not much going on here, much simpler than previous days. Enum.max() is used in part 2 because the beam is weird at the start, but that can be dealt with by using a point later in it.

Today’s puzzle was nice and easy, once I’ve got an idea how to solve it. Here’s my solution.

1 Like

After yesterday, this was nice and doable. :slight_smile:
https://git.sr.ht/~ihabunek/aoc2019/tree/master/lib/day19.ex

1 Like

I spent a good amount of time chasing a bad bug where my logic was right, even completed by hand in the shell to prove it, but using an un-updated map reference caused it to never find anything.

The moment I started uploading that video, I came up with a few ideas that cut down my part 2’s duration from ~20 to ~8 seconds, which is not as fast as I hoped it would be, but was a sufficient improvement to make a bonus video of it during my break: https://www.youtube.com/watch?v=ytqlVGO1-ME

E: this is after the fact but I thought of an additional optimization and now part 2 finishes in 500ms:

code is at: https://gist.github.com/ferd/9014a4623cbc483e3a101a89341799b6#file-day19-erl-L55-L59