Advent of Code
Yay, I did Advent of Code this year (a)! I did the entire thing until the end, although I did miss a few stars here and there. Those puzzles are really addicting, since most of them can be solved in under an hour. As long as you actually know the algorithm they wanted you to use (some pathfinding algorithm, probably), you're unlikely to get too stuck with the logic. Other than the pathfinding ones (aaa) there was only one problem I had no clue how to solve (day 11 part 2) and had to get help for.
Advent of Code is an excellent way to improve your skills in a specific programming language (or learn a new one!). Personally, I got better at Ruby. Choosing Ruby in particular meant I got to practice functional programming too, since Ruby has a lot of tools for it, which was a nice side effect. I also tried some clojure one day, although I didn't try it any more like I planned. The one regret I have with my programming language of choice is how SLOW it is. Usually that's not an issue, but for a few problems the most efficient solutions would finish in the tens of seconds, which means a ruby solution would take a few minutes. Day 24 was finished in C, because my initial ruby attempt was taking seven minutes to solve part1 (which takes 25 seconds or so for the C one).
I was competing for speed, but I'm bad so I didn't place well anywhere. I did manage to get on the global leaderboards once, placing 97th on part 2 of day 20. Other than that I was somewhere around the five-thousands or so most days. An interesting part of solving AoC competitively is creating a system and a set of tools that let you finish problems quickly. Usually a problem can be conceptualized in the sense of taking the input stream and shoving it through a series of filters that fondle it into more useful data structures, and reducing until you have your solution. Early on I tried making a little commandline tool for use with Ruby's interactive REPL to do this efficiently on a commandline. It maintains a list of functions that the input is filtered through in order, and the ultimate result is copied to your clipboard. I thought it was pretty cool when I made it, but immediately after I realized that it was dumb and all the problems I was trying to solve with it could also be solved by just... putting the solution code in a file that I could edit. Splitting things into small and contained steps still seems like the way to go though, since you can test each one after you make it to ensure you haven't messed anything up.
Speaking of messsing things up, I did a lot of that. Most of the time it was me failing to actually read the instructions like I was supposed to. There were also some annoying problems that made you "think outside the box" a bit for an easy solution. Day 5, for example, had some particularly hard text-parsing you had to do, but the hard part was a minimal portion of the overall input data so you could just as easily just... manually type it in to get a solution faster. I did not realize this.
There's also utility functions you can write to implement specific algorithms or data structures to help you solve things quicker. I didn't do this much because I had no clue what sorts of problems I was up against initially. I did do some of it later for pathfinding algorithms, though.
Here's some specific Ruby things I found fun:
-
Ruby's good at text parsing. It's also good at functional programming, so
you can get your input data into the form you want it pretty fast with some
wacky
/regexp/
andmap
combo. -
Need a grid? Just use a hashmap and use
[x, y]
arrays as keys. Or do it in three dimensions. Negative numbers work too and Ruby has good facilities for iterating over your keys. -
Ruby enumerators are nice and easy for more awkward iteration. For example,
iterating over the powers of 5 for day25 (b):
Enumerator.new { |y| x = 1; while true do y << x; x *= 5 end }
- Ruby is good at blending together imperative and higher-order programming.
AoC is great from a social standpoint as well. It's a nice thing to organize around and talk about. You can also use the AoC leaderboard as a social media platform. Just pick a random user that has a public github account or similar and click it and instant friends. Stress-tested by me.
I had fun overall! Will compete next year.