It has been almost a year since I worked on a university programming assignment, so I was starting to miss it. (Yes, it surprised me too.) Fortunately I ran into the advent of code this year, which was like a perfect advent calendar for me, as I am not really fond of chocolate.
Advent of code is an advent calendar for programmers, every day in December you can open a window and treat yourself with a programming task of varying difficulty. You can solve these puzzles in any language you like (even just on paper, if you have that kind of time!) and in addition you can have fun while reading witty task descriptions.
I managed to solve all 25 tasks, so I am a proud holder of 50 advent stars (as every daily task has two parts to be solved). You can check my Java solutions on GitHub.
I decided to write this short blog post just for myself, to summarise my thoughts and takeaways from the exercises. Any other person actually reading this will be considered as a nice bonus :).
Thoughts and takeaways
- I was really surprised by the times in which the best people on the leaderboard can finish the tasks. 2 minutes are unbelievable, it took me longer time just to read the assignments.
- That was one of the reasons I decided to take a non-competitive approach and just try to solve the tasks nicely and cleanly. (Another reason would be the necessity to wake up before 6 a.m.) Well of course I didn’t keep exactly this attitude till the end, but at least I tried.
- Usually I tried to go with the TDD approach, when I took the example data from the task and wrote a unit test for it first. Only after that, I started doing the real implementation. It worked very well, only in two or three cases I had a passing test and wrong result on my input data.
- Almost for every puzzle, choosing the right data structure for the problem was of very high importance.
- Around the third of the puzzles profited a lot from polymorphism.
- It has been only one year since I am out of the university routines, doing rather regular programming tasks nowadays. It kinda surprised me how painful the thinking about some of the puzzles was.
- Which were the hardest tasks for me?
- I started the day 3 with a mathematical approach, which really didn’t work well for the second part and it took a lot of swearing before I gave up and decided to solve the second part iteratively in just a few minutes.
- Day 7 (and especially it’s second part) took me also quite some time, but mostly because I was having a bit of a hard time understanding what is actually expected from my program to count.
- Hashing functions and bit operations in day 10 looked a bit scary, but the biggest problems I had were in the end with array reversal and ConcurrentArrayModificationExceptions.
- Generators in day 15 taught me that I shouldn’t be using integers or even longs, but rather stick to the BigInteger.
- Just the next day, 16th, was the first day when I started getting into trouble because of performance. I made a mistake to think that the dance can be described in repeating permutations and in the end I needed to read a hint on reddit to realise that I don’t actually need to calculate everything.
- Second part of day 17 was a bit similar. But after these two lessons I learned that I need to think more carefully about the assignment and don’t go straight for brute-force solution.
- 18th day took me quite some time to implement in OOP design (all that possibilities of instructions using a register or a literal), but when all the code was there, it was quite ok.
- Maybe I took a wrong approach to solve day 21, but boy, that needed even more code, all that fragment expansion and then reparsing it again to smaller fragments. And I also needed a little hint from reddit how to simply generate or flips and rotations of a fragment.
- Still, it wasn’t the hardest one for me. That was definitely day 23, with it’s assembly code analysis. When I peeked on reddit with previous puzzles, I was just impatient, but I could probably solve them alone, just in longer time. But here, I was quite lost in the woods.
- Overall, it was a lot of fun! (and hopefully next year it will be even more, because I want to try Kotlin for that)