Advent of Code 2021 - Day 18

My Elixir solution is similar to @danilagamma’s solution in that operates on the terms exactly as they are read from input file. That complicates the explode operation.

Browsing the solution thread on reddit, I saw that some of the solutions operates on a string or flat list, which simplifies the explode operation. Here is my solution in Erlang that uses that approach:

The explode and split operations becomes easier, while the magnitude and add operations become slightly more complicated. I also needed to implement a flatten operation, and an unflatten operation for testing.

3 Likes