bjorng
Advent of Code 2021 - Day 18
This topic is about Day 18 of the Advent of Code 2021.
We have a private leaderboard (shared with users of Erlang Forums):
https://adventofcode.com/2021/leaderboard/private/view/370884
The entry code is:
370884-a6a71927
Most Liked
ramuuns
soo much tedious debugging of recursion, but I love the fact that the parsing is pretty much just a Code.eval_string
also I’m pretty sure I shot myself in the foot for having each node be a {depth, [left, right]} as I think this was making some of the recursion annoying and it was easy to accidentally create the node wrong and whatnot.
Anyhow, both parts run in about 100ms - aoc/day-18.ex at 1542d38365d74533b324c4f790699767ce81b8e9 · ramuuns/aoc · GitHub
Update:
since I hate myself and apparently “enjoy spending a few more hours debugging recursion”, I implemented another version, that runs slightly faster where each node is a {depth, needs_split?, [left, right]}. Besides the ~10% perf improvement, it does slightly simplify the splitting operation at the cost of having to keep track if a node (or any of its children) need to be split. Code for the “improved” version: aoc/day-18.ex at 3419958dee43037aded833dc46c4fde183443add · ramuuns/aoc · GitHub
zevv
No sir, I did not at all like today’s puzzle sir. Every year there is at least one like those: too much text describing a tedious arbitrary process that’s a PITA to debug because you missed one of the many rules.
Anyway, I fought with a solution for too long where the numbers were stored as nested lists, but the recursion caused a pain behind my eyes. I fell back to just storing the numbers in a list, and exploding them by keeping track of a left and right carry that gets added to the next number to arrive. It suits nice with pattern matching, the end result is not too bad IMHO (even though some of the code looks more like Perl then Elixir), and fits in under a 100 lines,
bjorng
Here is my solution:
UPDATE: I’ve also implemented a solution in Erlang with a different internal representation that simplifies the explode operation.







