All my Advent of Code repos:
- AoC 2015 in Nim, Python
- AoC 2016 in Python, Clojure
- AoC 2017 in Nim, OCaml, Python
- AoC 2018 in Nim, Python, Racket (this repo)
- AoC 2019 in OCaml, Python
- AoC 2020 in Nim, one liner-y Python, Racket
- AoC 2021 in Python, Racket
- AoC 2022 in Python, Clojure
- AoC 2023 in Clojure
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.
Task | Nim Solutions | Python Solutions | Racket Solutions | Comments (on Nim solutions) |
---|---|---|---|---|
Day 1: Chronal Calibration | day01.nim | day01.py | day01.rkt | Dogfooding by using itertools to cycle through the input. Using IntSet for fast lookups. |
Day 2: Inventory Management System | day02.nim | day02.py | day02.rkt | The original solution used zip , but that allocates a new sequence. |
Day 3: No Matter How You Slice It | day03.nim | day03.py | day03.rkt | No 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 Record | day04.nim | day04.py | day04.rkt | [2018-12-04 06:00] Guard narimiran begins shift |
Day 5: Alchemical Reduction | day05.nim | day05.py | day05.rkt | 4x speed improvement when using the already shortened polymer (first part) for the second part. |
Day 6: Chronal Coordinates | day06.nim | day06.py | day06.rkt | The slowest task so far. |
Day 7: The Sum of Its Parts | day07.nim | day07.py | day07.rkt | Using heapqueue is a no-brainer here. |
Day 8: Memory Maneuver | day08.nim | day08.py | day08.rkt | Using recursion is a no-brainer here. |
Day 9: Marble Mania | day09.nim | day09.py | day09.rkt | Compile it with --gc:regions to get the most performance out of it. |
Day 10: The Stars Align | day10.nim | day10.py | day10.rkt | The first usage of Nim templates this year. Using unpack for <- sequence unpacking. |
Day 11: Chronal Charge | day11.nim | day11.py | day11.rkt | Using 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 Sustainability | day12.nim | day12.py | day12.rkt | Nothing to write home about. |
Day 13: Mine Cart Madness | day13.nim | Using 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 Charts | day14.nim | Using int8 to keep the memory usage down. |
||
Day 15: Beverage Bandits | Ain't nobody got time for that. | |||
Day 16: Chronal Classification | day16.nim | Nim bitsets don't have pop . |
||
Day 17: Reservoir Research | day17.nim | Recursion keeps things nice and simple. Templates help with the readability. | ||
Day 18: Settlers of The North Pole | day18.nim | Simplified boundary conditions by creating a border around the area. | ||
Day 19: Go With The Flow | day19.nim | Figured out the inner loop, do it "automatically". | ||
Day 20: A Regular Map | day20.nim | The 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 Conversion | day21.nim | The 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 Conversion | day22.nim | The first time in four years that I use A* algorithm for some AoC task. |