The coolest Advent of Code 2024 submissions [spoilers!]
I read every Advent of Code megathread so that you don't have to. Here are the absolute coolest approaches that were used to solve problems.
Spoiler warning! Close this tab if you don’t want to know anything about Advent of Code 2024. If you would rather see a compact list of cool projects, check out this Reddit community showcase.
Hobby projects are a recurring theme of software engineering. Many software engineers spend all day coding, and then go home and work on different coding projects at night. This sounds like a recipe for burnout, but this isn’t true for two reasons. First, since software touches so many facets of life, it’s easy to work on something completely unrelated to your day job. Imagine someone who maintains the bank website during the day returning home and working on their own video game. But more importantly, software engineers don’t burn themselves out on their side projects because they are notorious for abandoning these projects. Many people — myself included — have a graveyard of domain names that were purchased and never launched, or torn down after launch. But the fact remains: there’s an entire industry of people with the itch to code outside of work, but they don’t always have the time or interest to stick with a long-lived project.
Enter Advent of Code, run by Eric Wastl. It’s a yearly virtual Advent calendar featuring a daily two-part coding challenge. Every challenge has the same format: It explains the input data using some Christmas-themed story. It gives sample data for the coding challenge and might walk through an example. Finally, it describes the problem and asks for the secret output of the coding challenge1 that needs to be computed from a test file. You can advance to Part 2 by entering the secret correctly, and you are finished for the day when you have entered the secret for both Part 1 and Part 2.
But people don’t merely answer the problems. They answer the problems in unique and creative ways. They build amazing 3D visualizations. They run the code on 30-year-old obscure hardware or teensy tiny computers. They compete to be the first person to answer the problems and get showcased on the leaderboard for the day. They try to write code so fast that it solves every problem within microseconds. They MacGyver solutions that are so weird that you feel compelled to tell your other software engineering friends, “check this out, I had no idea you could do this!”
I didn’t participate this year2, but I still wanted to experience the joy of all of the creative solutions. So I read through every Reddit megathread to see all of the solutions the community discussed. I read through all of the other posts too.
Here is the coolest stuff I found:
Best in show: calculating an answer using .png filesizes
One of the most controversial problems was Day 14, part 2. The puzzle takes place on a 2D grid, where “robots” move through the grid based on instructions in the input file. Part 2 prompts you to enter the number of iterations until a Christmas tree appears.
This puzzle was polarizing! The problem did not explain what the Christmas tree looked like, and many people disliked this fact. On the other hand, some people were thrilled to have an open-ended question with many possible approaches.
Some people tried approaches like “finding T-shaped intersections” or “flood fill algorithms with heuristics” or “I manually examined all of the outputs until I saw it.” If you’re a programming language competition nerd and studied the behavior of the robots, this was a straightforward application of the Chinese Remainder Theorem. When my friend told me about this problem, I immediately wondered if I could make a simple edge detector using eigenvalue magnitude.
These were all fine. But Reddit user I_LOVE_PURPLE_PUPPY literally solved it by generating .png files of each iteration until he found one with a small file size.
For part 2, one pro strat is that you can save each frame as a PNG file and look for the ones with the smallest file size. The nice trees are compressible and will have a smaller file size and everything else looks like random noise.
That is so clever. Other users had similar approaches using other means of compression, but I’m giving the .png approach the top spot for producing its own visualization.
Biggest technology abuse: Vim keystrokes
Vim is an editor with a high skill floor and extremely high skill ceiling. It is a “modal” editor that allows you to quickly switch between modes that have wildly different capabilities.
Command mode. The default mode. This mode allows expert users to make any alteration or traversal of their document as quickly as they can think it.
Insert mode. Just enters text without any frills.
Execute mode. This allows you to use Vim’s terse scripting language.
So Reddit user Smylers solved the problems using Vim keystrokes. As in, he provided the exact keys that must be typed into a fresh Vim buffer to solve the problem.
[LANGUAGE: Vim keystrokes] This is for Part 2 only. I solved Part 1 in Perl, and while I could've translated it to Vim, doing modular arithmetic on each input line wouldn't've been very Vimmy. Whereas Part 2 pretty much demands a visual medium. Load your input, type the following, and watch the robots dance:
:%norm2x⟨Ctrl+A⟩lr|vbd⟨Ctrl+A⟩lrGplxr ⟨Enter⟩{4O⟨Esc⟩ka0⟨Esc⟩kk101a.⟨Esc⟩yy102p qaqqa:%s/X/./g⟨Enter⟩:%s/\v\d+\ze\| (.+),/\=(submatch(0)+100+submatch(1))%101+1 ⟨Enter⟩:%s/\v\d+\ze.*,(.+)/\=(submatch(0)+102+submatch(1))%103+1⟨Enter⟩ :g/G/norm yE@0rX⟨Enter⟩}j⟨Ctrl+A⟩ :norm/\vX{10}⟨Ctrl+V⟩⟨Enter⟩:%s/X/#/g⟨Ctrl+V⟩⟨Enter⟩⟨Enter⟩}jzb:redr⟨Enter⟩@aq@a
Or there's this version with added line breaks, for readability.
Start by turning each input position into the Vim commands for moving to that position in the file. So
p=50,78 v=89,45
becomes79G51| 89,45
— go to line 79 and column 51. Note both numbers are 1 higher, because Vim has neither line 0 nor column 0.Above that add a zero, for counting the iterations, and above that a row of 101 dots, which is copied 102 times.
Record the loop as a recursive keyboard macro. Start by returning all
X
s back to.
s, to reset the grid. There's nothing to do this first time, but as we're still recording the macro, the error doesn't matter.[another 5 long bullet points are omitted]
The amount of effort put into this technique is impressive. Yes, it takes very little for a program to be Turing-complete, so a scripting language should obviously be able to solve the problems. But then you would expect it to be provided using the Vim scripting language, not the exact keys that you press every step of the way. Smylers is clearly Mad Scientist material. The depth and breadth of the explanations is impressive. Well done.
Honorable mention to Reddit user jangobig, who solved day 3 with a similar approach using nano. I thought that nano was a trivially simple editor that did not have advanced scripting capabilities, so I learned something new!
Best programming environment: Baba Is You
In part 15, a robot is placed on a 2D grid with boxes. The robot is given instructions to move and the robot pushes any box it encounters.
This is straightforward in a normal programming language. Create a 2d grid, walk the robot through the grid, push the boxes, do the math. Simple and boring.
What if we didn’t use a programming language? There is an entire genre of puzzle games involving shoving blocks. My personal favorite is Baba Is You. In Baba Is You, each level has unique rules, and the rules are also embedded into the puzzles as pushable blocks, so you can change the rules of the game as you solve the puzzles. If you’re curious, here’s a timestamped link to a simple demonstration of the game’s mechanics:
Baba Is You comes with a level editor allowing the user to create custom levels. So what do we have? A game that simulates pushing boxes, has a level editor, and provides a way to issue instructions, and a problem that wants us to push boxes given a series of instructions. And sure enough, Reddit user jfb1337 used the Baba Is You level editor to simulate the example problems.
The final puzzle is too large to simulate in Baba Is You, and Baba Is You doesn’t perform the coordinate computation for you. So if you were a major bummer of a human being you might say “this is not a solution at all.” But I love seeing people solve Advent of Code problems outside of their code editor, and frankly I’ve seen so many Minecraft computers in my lifetime that I was excited to see people use another game to create a problem visualization.
Most cathartic: beating the algorithmic trap
Many Advent of Code problems have the same trap. Part 1 asks a question like “what is the solution after 30 steps of the simulation?” These are often trivially coded with an algorithm called “brute force.” This algorithm is what it sounds like: a dumb algorithm that solves the problem using computation muscle. It’s the computer equivalent of hiring a guy at the gym to keep running into your door until it opens. And then part 2 asks, “what is the solution after 30 quadrillion steps of the simulation?” and you do the math and it would take your program years to run. At that point, you can’t do the brute force approach anymore. You need a much more efficient algorithm. This is when you fire the guy from the gym, notice that the door says “pull” instead of “push,” and open the door a different and smarter way.
The subreddit is always flooded with memes on the days that employ this brute-force trap. And it makes sense; it’s disappointing to feel like you’re almost done for the day, only to have the real coding challenge begin.
Whenever I participated, I simply found the efficient algorithm like a sucker. I’ve always wished that the brute force algorithm would just work. The first brute force trap happened this year on Day 11, and Reddit user smalltailor7285 decided that Part 2 should also be solved with brute force, hell or high water.
I solved it properly using what we're all calling Lantern Fish.
But just to prove I could, I jumped on to our Databricks instance and literally looped it 75 times. Took about 3 minutes and cost $81.44.
How does this work? In Day 11, the problem gives you a sequence of numbers, and a rule for increasing the sequence of numbers that grows exponentially. Exponential growth is the type of growth that appears in virology (think COVID-19), where 1 person might infect 2 others, and those people infect 2 each, and it keeps doubling every iteration. When you hear of someone “going viral” this is what they mean - each user that sees your content is amplifying it to more than 1 other person. Exponential growth is the perfect kind of problem for an algorithmic trap, since you simply ask for the sequence length at the 30th and 75th iteration, and boom! The first one is possible and the second one is not.
In this case, the sequence of numbers was too large to be stored on a single machine. However! The final iteration “only” took up a few hundred terabytes. This means that modern cloud systems have no problem storing this list. And sure enough, smalltailor7285 became my personal hero by using a data storage platform to store the increasingly-large lists and generate the answer the good ol’ fashioned brute force way.
Nostalga factor: it’s the 90s, go for it
The old Windows 98 defragmenter solution to Day 9 part 2 brought back some memories. IYKYK.
And this solution was oddly reminiscent of Lemmings. Just a bunch of li’l guys trying their best and walking to their deaths.
Rapid fire: things I learned and other cool solutions
There is a programming language called Rockstar whose programs are written like the lyrics of a rock song.
Typescript’s type system is powerful enough for compile-time computation to work.
An surprisingly large number of people did the first few days in Uiua, a stack-based array programming language that I had never heard of.
I learned how Uiua is pronounced (wee-wuh).
I learned of the existence of the Cardputer.
At least one of the problems was actually solved on a quantum computer.
Usually a number or a short word.
My daughter had a horrible case of the flu last Christmas. She couldn’t sleep at all. So I held her upright from 4am to 7am so that she could get even 3 hours of sleep before her first Christmas. With my other hand, I slowly typed the solution for the final day because I wanted to spend the entirety of Christmas Day with my family. After I got the answer, I decided that I would take a few years off from Advent of Code because life with a small child is too demanding to allow someone else to control so much of my schedule. I had a lot of fun getting 50 stars with zero hints in 2021, 2022, and 2023, and I’d like to do it again in the future when I have more time.