[go to last puzzle] or [go back]
Day 1: Dusty Shed
Conveniently, last year's day 8 puzzle also involved finding the largest three groups,
so I was able to adapt that code. The only issue I encountered was forgetting that I
put the input file in memory at address 0, so when I tried to store my numbers there I
got ridiculous values.
The second part was basically the exact same, only new thing was a check for groups of 0
so I didn't claim 1, 2, and 3 as the smallest groups
Day 2: Fulminating Farmland
I do love me some cursed math. After seeing the puzzle input,
I decided to brute-force some modulos to avoid making a lookup table.
I ended up with (((ord^2) % 2128) % 1224) / 229, which cleanly maps the ASCII values of roygbv to 0-5.
This one changed the problem into a counting one, since the best way to maximize distance always involves doing the same color as many times in a row as possible.
Once a color is exhausted, the next available color walking backwards in the cycle
maximizes distance traveled. And since the robot starts on red, starting with all red moves is best.
So, I could just count how many of each color command was present, and play them back in r-v-b-g-y-o order.
Day 3: Foggy Forest
Got to do some more robbery from last year's day 4 for the grid reader!
Once the input was loaded into memory, looping through all possible squares
wasn't hard, once I remembered that it was squares and not rectangles
and stopped clobbering the input with data while I was still reading it.
Thanks to the magic of WASM, even adding a new inner loop for how much to shift the corners in a circle
was still fast (once I fixed an accidental infinite loop ._.)
Day 4: Perilous Pier
The theoretical method for this one wasn't hard to find - assume a pattern of length 1 will work, fill in a pattern with values from the barcode, retry with one more length if any value conflicted.
Did have some errors along the way, regardless:
- When reading in the barcodes, I stored the length and contents. However, I didn't correctly set the write pointer for new rows and ended up clobbering the length with the barcode contents instead.
- Once I had everything written, I looped through every barcode. I read its length, and then promptly forgot it was a number and not a pointer and so used it as such, resulting in odd-sized rows.
Buuuuut it all worked out :D
This was probably one of the easiest part 1 -> 2 conversions of all time: just ignore newlines (and adjust a few things to handle bigger lines).