Sunday, December 27, 2015

Advent of Code 2015


Over the past month, I've been slowly working on the Advent of Code programming puzzles. I was alerted to this by a colleague at work and decided to give them a try. You get one puzzle each day, with two parts, and solving them gives you a star to light up the Christmas tree (since this was in December and holiday-themed). I decided to use Python to solve these as it's one of the programming languages I know best, but any language would have worked.

Below, I describe a few of my favorite puzzles, the hardest ones I found, and things I learned from this.

It was overall very fun and I am happy to say that I was able to solve them all to my satisfaction. Nevertheless, I am not the best programmer and a couple of times I struggled. Fortunately, a subreddit existed where people shared hints and solutions and that helped immensely.
While I've taken some courses in programming languages, these were a long time ago and I never took the more advanced classes in computer science that introduce some of the classical problems. For example, there were at least two puzzles (days 9 and 13) that were basically the Travelling Salesman Problem. I didn't recognize it as such until the second puzzle when I looked to the subreddit and realized how much easier it was to approach the problem that way.

The most difficult ones I remember were days 7 and 19, for which I had to look up and extensively study the subreddit to figure out how to even start. For day 7, we had to emulate a circuit board with bitwise logic gates and had to figure out the signal in a specific wire, but only after all wires had processed their signals. Clever looping and handling of error exceptions, as well as parsing the input strings to execute them properly, was needed to solve this. For day 19, we were given a string "molecule" and a set of instructions on how to replace "elements" in the molecule. By then, my programming skills had improved and I was able to solve the first part without trouble, which was to check how many unique molecules could be created by making a single replacement. The second part was much more difficult as it asked us to find the minimum number of replacements to go from a single electron all the way to the input molecule using the given instructions. That was a lot harder than it sounded, but the subreddit had some good comments explaining several approaches to this.

Some of my most enjoyable ones were the two RPG games we created: days 21 and 22. The first had us minimize, or maximize, the amount of money we spent in equipment to win a fight. The second had us minimize the amount of magic we used to win the encounter. These were fairly straightforward, but required carefully coding and reading of instructions so that you didn't miss anything.

In the end, this was a fun set of exercises to practice some programming. Some were hard, some were easy, but at the end it was very satisfying to have a solution for all of them, even if I had to have some help. All my solutions are in a github repo and while they are not necessarily the best, fastest, or most elegant, it nonetheless serves to store these for the future in case I encounter similar programs again.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.