Home

Awesome

Advent of Code 2018

All my Advent of Code repos:

This year, I will do it once again in Nim, and later on maybe in some other language too in October 2021 I practiced Racket by solving some of the puzzles, and some time before that (in 2021) I also solved the first half of the puzzles using Python.

For Nim solutions, my aim was to provide clean, readable, idiomatic code. Python solutions extensively use lambda, and the aim was to provide short (but still readable) solutions. I'm a beginner in Racket, so the solutions here are part of my learning of the language, and consequently might not be idiomatic.

 

Solutions

TaskNim SolutionsPython SolutionsRacket SolutionsComments (on Nim solutions)
Day 1: Chronal Calibrationday01.nimday01.pyday01.rktDogfooding by using itertools to cycle through the input. Using IntSet for fast lookups.
Day 2: Inventory Management Systemday02.nimday02.pyday02.rktThe original solution used zip, but that allocates a new sequence.
Day 3: No Matter How You Slice Itday03.nimday03.pyday03.rktNo need for regex, scanf macro is great for these kinds of inputs. Using smaller integers instead of int gives noticeable speed boost. Using templates to keep the main part short and readable, without unnecessary repetitions.
Day 4: Repose Recordday04.nimday04.pyday04.rkt[2018-12-04 06:00] Guard narimiran begins shift
Day 5: Alchemical Reductionday05.nimday05.pyday05.rkt4x speed improvement when using the already shortened polymer (first part) for the second part.
Day 6: Chronal Coordinatesday06.nimday06.pyday06.rktThe slowest task so far.
Day 7: The Sum of Its Partsday07.nimday07.pyday07.rktUsing heapqueue is a no-brainer here.
Day 8: Memory Maneuverday08.nimday08.pyday08.rktUsing recursion is a no-brainer here.
Day 9: Marble Maniaday09.nimday09.pyday09.rktCompile it with --gc:regions to get the most performance out of it.
Day 10: The Stars Alignday10.nimday10.pyday10.rktThe first usage of Nim templates this year. Using unpack for <- sequence unpacking.
Day 11: Chronal Chargeday11.nimday11.pyday11.rktUsing summed-area table to have O(n^3) solution (naïve solution is O(n^5)). Using threads gives 2x speed boost.
Day 12: Subterranean Sustainabilityday12.nimday12.pyday12.rktNothing to write home about.
Day 13: Mine Cart Madnessday13.nimUsing complex plane is the obvious choice for the tasks like this, but complex in Nim is limited to floats, so I decided to use plain old tuples of integers.
Day 14: Chocolate Chartsday14.nimUsing int8 to keep the memory usage down.
Day 15: Beverage BanditsAin't nobody got time for that.
Day 16: Chronal Classificationday16.nimNim bitsets don't have pop.
Day 17: Reservoir Researchday17.nimRecursion keeps things nice and simple. Templates help with the readability.
Day 18: Settlers of The North Poleday18.nimSimplified boundary conditions by creating a border around the area.
Day 19: Go With The Flowday19.nimFigured out the inner loop, do it "automatically".
Day 20: A Regular Mapday20.nimThe initial solution first created a maze and then DFS-ed through it. Current solution immediately calculates the distances, for 3x performance gain.
Day 21: Chronal Conversionday21.nimThe most interesting part of the task (figuring out what the instructions really do) was done on paper. Here is a part of it.
Day 22: Chronal Conversionday22.nimThe first time in four years that I use A* algorithm for some AoC task.