About AoC
Advent of Code (AoC) is an advent calendar of programming puzzles developed by Eric Wastl, started in 2015. Every day from December 1st until December 25th a new puzzle is revealed, at 5AM in UK time. Each puzzle has 2 parts. In order to unlock the 2nd part, you need first to submit the correct answer for the 1st one. There's no time limit to complete the puzzle (you can still do them now), but the first 100 people to complete the puzzle get a score. It's very hard to get in the ranking, though, since it seems the fastest people complete them in under a minute (is that even possible? I need several minutes to read the problem... 😅), and there are lots of people attempting it. This year started with more than 200K people taking part. If you are in the UK, you also need to wake up early (I can't 😂). However, puzzles get slightly harder as days progress. Weekends tend to be even more challenging. So if you don't give up, you may get higher in the rank. I was 44K in the ranking of the first day, but ended up 5K in the 25th. The site provides also some interesting stats so you can see the completion rate of each puzzle.What for
You can do it to compete, or simply to practice. In my case, it was mostly to practice. I'm usually busy with side projects so I never really thought that I wanted to give myself even more programming work. But this year I haven't done much programming on the side, so I was starting to forget Swift a bit, since it's a language I only use in my side projects. But I had to check something in Swift for work, so I thought that doing this year's AoC in Swift would be a good way to warm up. I like Swift, and the problems were fun, so I quickly got into it. Although at a later date I started to get tired. On Christmas day, the first part wasn't that difficult, but the 2nd part was simply to collect all the stars from the previous days... 😅 I had 3 unfinished puzzles (or rather, 5 parts), so I did a bit of a programming marathon to finish them all and I ended up a bit tired 🙈 Although once done, it's a great sense of accomplishment. 👍How to approach it
As you like, really. But what I've done is creating a single project where I put all the files for all the puzzles. It's a CLI app that I always invoke passing a file named something like day12_input.txt, or day23_example1.txt. From the name of the file I get the day number, and then I execute the corresponding dayXX function, from a big switch-case (I thought of using reflection to invoke the right method, but Swift's Mirror API lets you access only the attributes, not the methods). I distributed these functions in files named WeekN.swift, 7 days per file, just because I don't like huge files. For short exercises, I write the algorithm inside that day's function. But in most cases I create a separate file with the functionality and invoke it from that day's function. See below, after 25 days. Having it all in a single project has been useful because I could reuse some of the code. I kept refactoring as I went, to make the code more useful. I also started adding test functions. I invoked these test functions from the corresponding daily function, although perhaps I could have created a separate test project. But at this point, it's perhaps overengineering the problem. 😅 Debugging code can also be fun, even when unnecessary. I tried doing some visualizations of the problems to help me debug, but also because it's cool. There are people in Twitter generating images and animations for some of the problems. Here are some interesting ones I found: day 15 (search), another day 15, day 14 (polymerization), day 13 (origami) in C64, and day 13 animation. I wrote some code to export my image-like structures into images and create animations with the steps of the algorithms, and here are some of the results: day 11 (flashing octopus), and day 9 (smoke basin).Conclusion
Try it. Even if you don't know any programming, it may be interesting to read the problem and try to figure out whether you can solve it mathematically or on paper. Sometimes, it can be fun just thinking on how many permutations of a particular problem there are. Perhaps plan in advance when you are going to attempt solving the problems. I happened to have some holidays so I could spent some hours every day on AoC. There are better things to do on holidays, perhaps, but you can always take some paper with you and think about the problem while resting at a coffee shop (restrictions allowed). Thanks to Eric Wastl for all the time spent creating these puzzles. 😊Tweet