This blog post is a work in progress
Project website: Advent of Code 2018.
I use Perl for all the solutions.
Most assume the input data is in a file called
input.txt in the same
directory as the file.
A note on scoring
I score my problems to mark where I’ve finished a solution myself or given up and looked for hints. A score of 2 means I solved both the daily problems myself, a score of 1 means I looked up a hint for one of the problems, and a zero score means I didn’t solve any of the problems myself.
My goals for this year (in descending order of priority):
- match or beat last year’s score of 49/50.
- solve all problems within 24 hours of release
This year’s todo list:
- Not completed
Complete day 23 part 2
- Complete day 20
Complete day 17
- Complete day 15
- Completed, not published
Publish day 21
- Day 16 - solve part 2 without manual intervention.
- Day 14 - faster part 2.
- Day 12 - rewrite part 2 to find the answer programmatically.
Day 22 - rewrite part 2 to use A*.
- General - implement blogging and listing publication using templates
Publish day 18 Day 8 - clean up and publish solution Day 11 - faster solution
Day 1 - Chronal Calibration
Investigate the properties of summing an infinite list of integers.
A nice start to this year’s puzzles.
I had planned on getting up at 6AM to start with this but I spent the night before playing Fallout 4 so that didn’t happen.
Day 2 - Inventory Management System
Investigate the properties of the strings given as input.
Another O(n^2) solution, but for the small sizes involved it barely matters.
Perl’s string munging is helpful as always.
Day 3 - No Matter How You Slice It
Investigate the properties of overlapping areas given as input.
Nice and clean. I was worried I’d have to do some complicated lookups to single out the correct swatch in part 2, but it turns out that there was only one possible solution in my input.
Day 4 - Repose Record
Given a list of activities, determine properties about the times these activities occur.
Getting the correct answer without resorting to an external run
sort -n was the hardest part of this problem!
There are some nice solutions using a Schwartzian transform out there but to be honest I’d rather have something straightforward and dumb that can understood later.
TODO: better variable naming.
Day 5 - Alchemical Reduction
Remove elements from a list, based on rules on which neighbors an element has.
A quick and simple problem.
Day 6 - Chronal Coordinates
Investigate areas on a grid, expressed in Manhattan coordinates.
Keywords: Voronoi diagram
This took some careful perusal of the text and example to figure out. I had a lot of problems with my solution when I tried to merge part 1 and part 2 into one solution. Unfortunately I had overwritten the code that actually gave me the first star, and I broke it.
I felt justified to check out other solutions and finally re-wrote using those (essentially using a representation of the board to keep track of the data). The day after I took the time to re-write it again into a version closer to my original idea.
Runtime is a dismal 16s.
Day 7 - The Sum of Its Parts
Find a path through a graph, given that some steps must be done to proceed.
Keywords: DAG, directed acyclic graph, topological sort
I’m really happy with solving this. I’m graph-aphasic, as in I’ve never ever grokked them in code, and was dreading finding some random Perl module that I didn’t really understand. In the end I just found the “endpoints” and processed it using a queue.
This made part 2 reasonably easy to code.
Day 8 - Memory Maneuver
Investigate the properties of a tree structure given in the form of a string of integers.
Keywords: tree structure, recursive
I had a lot of trouble with this, which wasn’t helped by stuff like people coming over to visit, dinner to cook and eat, and wine to drink. After these distractions were done with I could revisit the problem with fresh eyes.
Day 9 - Marble Mania
A game is played by placing marbles in a circle. Investigate the end state given the puzzle input.
Keywords: double-ended circular list
This was a fun problem that was marred by some irritating off-by-one errors in the results. We were blessed with a wealth of example inputs, and I could make most of them work by taking the largest or the next largest value. This gave me my second star, but it was hardly repeatable.
Double-checking my logic against other solution revealed I was thinking correctly, but had a stupid overrun where I managed to take more marbles than were actually available…
Runtime for part 2 is 30s, but you need quite a lot of memory to run it. My wimpy VPS cannot run it natively.
Day 10 - The Stars Align
Given a number of points, their positions and velocities, investigate whether they form a coherent message when printed.
A nice palate-cleanser after the horrors of the week-end.
Day 11 - Chronal Charge
Investigate the values of subsquares on a 300x300 grid.
Keywords: summed-area table
Trying to solve part 2 using brute force took 173 minutes. Implementing a summed-area table reduced it to 3s.
Day 12 - Subterranean Sustainability
A number of plants grow in an infinite line of pots. The existance of a plant for the next generation depends on its neighbors. Investigate what plants remain after a number of generations.
Keywords: cellular automata
This was a fiddly one. I got bit by the shallow copying nature of
Perl’s data structures, but implementing the
Clone module took care
Then is was just a question of dealing with the inevitable off-by-one errors.
Part 2 was found by reasoning that the pattern would stabilize, and after that is was just a matter of finding the pattern and identifying the offsets.
My Part 1 code can either give the answer to the question with no input, or output some useful metadata if given another argument.
Part 2 answers the question by default, and gives the value for an arbitrary input if that’s given as an argument.
Day 13 - Mine Cart Madness
Carts move along a track with turns and junctions. Determine whether they collide.
I’m both proud and ashamed of this one. Proud because my basic code determining how the carts move was correct from the get-go. Ashamed because it took me all day to figure out the collision detection.
Day 14 - Chocolate Charts
A list is generated programmatically. Investigate its properties as it grows.
Keywords: pattern matching, brute force
Not my favorite problem, not least because my brute-force solution is killed by my VPS.
Runtime for part 2: 2m14s.
Day 16 - Chronal Classification
An obfuscated register manipulation routine is presented. Solve the program.
This years Register Rodeo! It was fun apart from the horrid input parsing.
Day 18 - Settlers of The North Pole
Investigate the properties of a Game of Life setup.
Keywords: game of life
A scruffy solution. I had no problems with part 1, but part 2 was plagued by off-by-one errors.
Day 19 - Go With The Flow
Decompile a deliberately inefficient algorithm.
Keywords: registers, decompilation
Decompilation problems are not my favorite problems.
Day 22 - Mode Maze
Find the quickest path between two points on a graph.
After some struggle, I finally figured out a good way to conceptualize this.
Right now I’m using straight Djikstra’s which is way too slow.
Edit 2021-01-09 it turns out my issue wasn’t with the Dijkstra’s algo per se, but instead with my implementation of the required priority queue. After using a high-performance version from CPAN I got my runtime down from 15 minutes to around 2 seconds.
Day 24 - Immune System Simulator 20XX
Man, this was a slog. I coded it all myself, but got help online from working solutions to figure out where I was doing it wrong.
Part 2 was found manually.
Day 25 - Four-Dimensional Adventure
Investigate points in 4D space.
Last problem this year. Figured this out through brute force.
Score: 1 (final star only awarded if all other solutions are done!)