Skip to content

ZoomRmc/aoc2022_nim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

aoc2022_nim

AoC 2022 in Nim

Join Nim-AoC Matrix room

Previous years:

General notes

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

Notes on specific days

Spoilers below!

Day 13

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

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

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

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

Day 9 spoiler Nothing unusual, this day favours separating primitive routines into their own procedures and writing clean simple logic.

Day 8

Day 8 spoiler Again, no-tricks imperative code with branching, loops in breaks in my initial solution.

Day 7

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

Day 6 spoiler The day where easy beats smart.

Day 5

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

Day 4 spoiler

No real twist here, just have to be careful when considering edge cases, especially for overlapping.

Day 3

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.

Day 2

Day 2 spoiler You can spend a lot of time juggling modular ops and end up with an impenetrable and bug-prone code. Just make a neat LUT! Both solutions provided.

Day 1

Day 1 spoiler Using provided `sort`/`sorted` routines is just lazy! Manual branching is absolutely fine, but a generalized routine to keep track of biggest numbers in an array may come handy later.

Releases

No releases published

Packages

No packages published

Languages