My Advent of Code 2022 Journey
What's Advent of Code?
Advent of Code (AoC) is a fun coding challenge that occurs between the 1st to the 25th of December, although you can go back and do the previous years challenges whenever you want! Each day brings a new story, with you trying to solve a problem to help the Elves out. It's not like your typical coding challenges that Codewars or LeetCode offer, instead a deeper more playful story-driven challenge.
The problems during the month get harder and harder, but not linearly - some days are easier than others, sort of like a "break day". The story each day comes in two parts, both earning you a single star working towards your goal of 50 starts on December 25th. Part 2 is usually an extension of part 1, but later in the series I found that part 2 meant you needed to re-write everything you did in part 1 if you used a brute force approach to the problem.
I've done quite a lot of these types of programming challenges before, especially on Codewars and one big difference between AoC and the others is that AoC forces you to think through your solution before you submit an answer. If you submit a wrong answer, you'll get locked out temporarily, this sounds scary but each problem provides a sample set of data and the expected answer, so you can test your solution on that first.
I still haven't gone back and finished all of the challenges. I got up to day 16, and all of my work is over at korziee@github.
Languages
During the beginning of the month the challenges were fairly trivial, so I spent some time playing around with a few languages that I haven't written in before. Towards the end I fell back to TypeScript as that's the language I'm most proficient in.
V Lang
I did a couple of challenges in V and I enjoyed it as a language, it was easy to pick up and get going, even though the documentation was scattered and not easy to search. It felt like a nice balance between Go and C. V offers a nice standard library, good control flow, and simple error handling. One downside that I found with V was the lack of editor tooling - the VSCode plugin wasn't bad, it had nice syntax highlighting, but was lacking autocomplete.
Erlang
I've been meaning to check out Erlang for quite a long time... Ever since a tech bro ridiculed me for 5 minutes after I said I use NodeJS primarily in my work, and they wouldn't stop talking about Erlang!
I found Erlang quite tough, I don't have much experience with functional languages, so it was a bit of a paradigm shift. But once I got the hang of pattern matching I started to enjoy it. Although I couldn't stop thinking about just how inefficient this code would be at runtime?
At this point, I thought I'd just been spoilt with TypeScript intellisense and just had high expectations for editor integrations. There are a couple of Erlang VSCode integrations, and the one I used was good enough, but as a newbie to the language I still found some features like autocomplete for the standard library lacking.
Go
Go has got to be the most boring language I've ever written in, and I love it! The simplicity of Go makes it a enjoyable language to work with. I was pleasantly surprised by the VSCode integration as well, I found debugging to be a breeze, and formatting just worked. The Go documentation was great, I did the Tutorial: Get started with Go and really enjoyed the tour of the language!
C
C - Bit of a classic! I find opportunities to use C day-to-day are extremely rare in my line of work (web) so I did day 6 in it and had a great time. Theres something so humbling about dropping down into C and doing things from scratch.
Swift
HOW GOOD IS SWIFT?! I used Swift a fair bit back when I did my stint in the Connected Television Team (CTV) at Nine working on the 9Now Apple TV application. if let
and named parameters are such nice parts (among many more, but these two come to mind) of the syntax. Swift in VSCode isn't great, but I was trying to avoid whipping out Xcode just for AoC.
Gleam
Gleam is what Typescript is to JavaScript, but for Erlang. It transpiles to Erlang. It was an extremely enjoyable (borderline bubbly) language to use. The documentation was phenomenal and helped expose me to a lot of concepts that could also be used in Erlang.
In-line error handling was rather enjoyable through the assert
operator.
assert Ok(file) = file.read(from: "input.txt")
From the docs:
Sometimes we have a function that can technically fail, but in practice, we don't expect it to happen. For example, our program may start by opening a file, if we know that the file is always going to be possible to open, then we don't want to complicate our program with handling an error that should never happen.
Core Learnings
- READ THE FUCKING QUESTION SEVENTEEN TIMES BEFORE YOU TOUCH THE KEYBOARD!
The further I got into AoC, the more and more frustrated I got (at myself) for not fully understanding the problem before I started solving the problem. I had many teachable moments, as I often jump the gun and just start pseudo-coding a solution to aid my thinking. Usually that's beneficial to what I'm doing, but in my experience, it was just wasted time, as the problem develops throughout the entire story.
- Don't spend hours on end trying to solve something, reach for help/hints
This is tied with core learning #1. AoC is meant to be a fun challenge, not a hair-pulling, aging process. I think I would've gone through to day 25 if I had time-boxed my attempts at some of the challenges, and after that reached for help if I was stuck, in the form of hints or reviewing other people's solutions. The AoC subreddit is a good source of knowledge. You truly don't know, what you don't know. There's no point grinding unnecessarily and getting frustrated. Instead, learn by reviewing and understanding.
- Do not eagerly optimise for part 2
Half of the battle with AoC is groking the problem provided to you in the form of a story, for me, over-optimising early took up a bit too much brain space. I was better off solving the solution with a brute force approach, which gave me the mental capacity to at least understand the problem completely. Rather than spending time optimising and crafting a beautiful algorithm!
Closing Thoughts
I enjoyed AoC 2022, but knowing what I know now by reflecting on AoC 2022, I'm going to really enjoy AoC 2023! You can do the previous years Advent of Code whenever you want, so check it out, get your friends and co-workers on board, and happy programming!