Programming, coding, software development, whatever you want to call it – it’s a craft. It’s art and science.
As a kid, I got into computers, as a teenager I really got into buying parts and putting computers together, and in my senior year of high school I finally started programming them. As an assignment, I wrote a Wheel of Fortune app in BASIC. My high school classmates would come to me for help (the notes in my yearbook reminded me of this), and I would do it because I loved it! I didn’t have a lot of craft back then, just a little native ability.
Every time I solve a problem I’m reminded why I do what I do. For me, there’s not much else that compares with the feeling of “I just figured out this really hard problem.” I love the hard problems. I seek them out. The adrenaline rush of “figuring it out” can be highly addictive.
After coding for almost 20 years (10 years here), the problems that present themselves on a day to day basis are not fresh. They are rehashes of problems solved during the good old days when new problems were coming at you left and right – when you would use more the CPU of your brain, and less the memory!
I make it sound pretty glum, don’t I?
So, two years ago (plus a week or two), I heard about a programming challenge called Advent of Code. Like the Advent Calendar in the Catholic faith, every day you open a door, until the 25th. It creates the suspense and helps you keep track of how many days there are until Christmas. The idea of Advent of Code is similar, in that every day you are presented with a new puzzle. However, in the traditional Advent Calendar, you aren’t competing with your friends to open the door first and you’re not posting screenshots of how many doors you’ve opened! So, it’s a little different.
The most intriguing part of Advent of Code is that “these are problems I may not have solved before!” And they happen every day for 25 days! Here is the main formula that AoC follows:
Every day you solve problems to progress the story. The puzzles then feel tied together and you want to push the protagonist forward. 2015’s story was themed towards elves, 2016’s towards the Easter Bunny (?), and 2017 seems to be “you are inside of a central processing unit,” I think.
Every puzzle comes in two parts. At midnight the puzzle unlocks and you are given access and your input. The input varies somewhat for each person. Each time you solve a part of the puzzle, you are given a star! Every day you can earn two stars. Part 2 of the puzzle is only revealed after Part 1 is solved and it usually involves the same input and would vary how it’s processed.
(Quick note on Part 2s in general: Part 2s are not fun. You wrack your brain at Part 1, find an awesome solution and think you’re mostly done! Then Part 2 rears its ugly head. It is not a simple modification a lot of the time. It is a ground-up rewrite!)
There is a leaderboard, however, I am usually not in a huge rush to make the leaderboard. I tried one time, and I was done the solution in 10-15 minutes and was nowhere near the leaderboard. I simply enjoy the opportunity to solve the problem.
The community is great -friendly, helpful. There is a subreddit ( https://www.reddit.com/r/adventofcode/ ) where people will post their solutions in their favorite language, ask questions, get advice, and learn. Learning is what happens most.
You’ll see messages like “Hey, I answered this but it takes 3 minutes to run.” They’ll post their code, and someone else will follow up on how to make it faster! Or better! Or cleaner. Sometimes people will “almost” have the right answer, and will be helped along.
After the leaderboard has filled up, the daily “solutions” thread opens up where people can then start posting their solutions. Often this is filled with head scratching on my end, as I thought my solution was pretty clean, concise, etc, and some people are posting one-liners. There are a lot of interesting languages out there as well-another takeaway.
In 2017, the problems have not been too difficult. However, they don’t tend to get challenging until about the 10th. So far, I’d classify the problems I’ve seen over three years as follows:
DFS / Tree Search
These would be the problems like traveling salesman and pathfinding type of problems. These are very interesting.
With these problems, you’re typically given a large grid, sometimes described as “infinite in scale” (just meaning, for the sake of the problem, there are no bounds). These sometimes also involve pathfinding, but a lot of time they are math based. Also, Conway’s Game of Life made its way into a problem one year.
These problems typically give you an assembly-like programming language that you have to write an interpreter for, and execute a given set of code against! These are fun but can be a little bit tedious.
With these problems, you’re usually given a simple set of rules and then a massive text file to process.
An interesting problem this year was Day 3, which involves a grid, and a spiral! You come across an experimental new kind of memory stored on an infinite two-dimensional grid. (Ah, the good old infinite two-dimensional grid.)
Language and Code
I write my solutions in Go (by Google). I have been interested in learning new programming languages, in trying to sooth the same itch that makes me want to solve new problems everyday. Go is fast. It’s actually fun to write. And I think, being a very biased beholder, that it’s beautiful. My solutions for the past 3 years are up on github.
I feel comfortable sharing all of my code, because the Advent of Code spirit is “we are here to learn”. Tell me a better way to do something. I welcome it!
Most Interesting Problems
Here is my list of three very interesting problems from AoC over the years. A lot of them I’d say were very interesting, but I narrowed it down to three. (Reminder, part 2 won’t be visible unless you’ve solved part 1 first).
My solution – 79 lines of code
This is a prime example of “Part 2 Mayhem”… Part 1 just involves looping around a circular array. Ok, that wasn’t so bad. Put in the answer and it’s right. Ok, on to part 2. Blank stares ensue. Oh! I just have to rewrite it to use a linked list and pointers to keep track of the “across” elf. No problem.
2016 Day 11
Just read this one. It’s the “Goat, Wolf and Cabbage” problem, but much more complex.
My solution – A bit of a monster at 280 lines. Proud moment in solving this one.
2015 Day 22
This one was my favorite. Little Henry Case. You’re a wizard!
My solution – Beefiest one of my list of 3, coming in at 310 lines of code. The general idea here was to throw randomness at it until you find something that can’t be bested which also meets all of the criteria of the puzzle.
Difficulty! And Statistics
As the days go on, either people become less interested or the challenges become much harder! The numbers are there. Following the stats for 2015, 31K + people got two stars for day 1, but that number dropped off significantly by day 25, to just 2047! In 2016, the initial number started at only 14K, but only around 1500 people have both stars for day 25. For 2017, the initial number is back up to 27K+ solving both parts on day 1.
There are personal statistics for each day as well. Last year I was highly distracted and didn’t start solving puzzles until 2 weeks in, so all of my stats are “> 24 h”, but in 2017 I’m starting them on the day… maybe staying up until midnight to do them… but don’t tell anyone 😉
I would highly suggest doing these puzzles! They are fun, challenging, and rewarding. Why else do you write code? I also have a private leaderboard set up–if you want to join, shoot me an email at firstname.lastname@example.org and I will pass you the leaderboard code!
Happy Coding and Happy Holidays!
Need some help from our best-in-class engineering team? Let’s chat.