AoC 2022 in Nim
What I'm trying to stick to while writing the solutions, in order of importance:
- Intelligible implementation logic, clear data flow
- Brevity must not hurt readability
- Short, self-sustaining functions with evident behaviour, hopefully as "strict" as reasonable
- Keep the solutions for both parts of the task separated (one should work in case the other was removed from the code), extract repeating computations to functions/templates
- Use the more suitable data structures available (it's tempting and boring to solve everything with Hash Tables)
- Explore standard library before jumping to external libs
Spoilers below!
Day 13 spoiler
Who would have thought, another recursive parsing task on aour hands. I don't know nothing about that, so a boring state machine it is. No cheating with `eval` of heterogenous arrays that those interpreted languages tempt you to use!Day 12 spoiler
Another day, another path found. The interesting bit is a new variation of the `Neighbours` iterator, this time with a set and a single yield.Day 11 spoiler
As is common for AoC, this would be a nice task, if not for tedious parsing, especially considering I manage to forget how Pegs work during the year! Keeping a lambda in an object and using bool-indexed array is very satisfying.Day 10 spoiler
Again I opt for separating parsing and executing commands. The fact it's easier to reason about the bugs this way is a bonus.Day 9 spoiler
Nothing unusual, this day favours separating primitive routines into their own procedures and writing clean simple logic.Day 8 spoiler
Again, no-tricks imperative code with branching, loops in breaks in my initial solution.Day 7 spoiler
We could get the total sizes for each folder while parsing, but I opted for building a clean proper filesystem while parsing and walking it for the first part. Not much reason to change it for the second.Day 6 spoiler
The day where easy beats smart.Day 5 spoiler
Parsing the initial state is the hard part. My initial solution for this is as imperative as it is ugly, but at least it's one pass over the input. Actual execution is a no-brainer.
Day 4 spoiler
No real twist here, just have to be careful when considering edge cases, especially for overlapping.
Here's some words missing from this day's description:
the Elves are divided into distinct non-intersecting groups of three
I almost thought it's going to be a combinatorial hell! Otherwise, system:set
make it a breeze.