This site uses different types of cookies, including analytics and functional cookies (its own and from other sites). To change your cookie settings or find out more, click here. If you continue browsing our website, you accept these cookies.
Discussion thread for day 18 of the Advent of Code - https://adventofcode.com/2021/day/18
Surely there's a better way than so many multi-row formulas and nested macros
My code was super slow and super ugly, but I got the right answers
Well, it works. eventually.
messy chained and ugly macros. Takes forever to run (several hours). Will certainly look into the other solutions for ideas 🙂
Spent a good deal of time on this - specifically to break it down into logical modules, each of which had 1 responsibility. This runs in a few seconds in AMP
Similar to @clmc9601 , @patrick_digan and @dsmdavid - lots of use of embedded macros and multi-row formulae.
I built most of this from the bottom up in a TDD way (built the test harness first) - @SteveA would be proud!
Magnitude Calculator:
The adder Loop:
The algo here is relatively simple:
For each unique experiment ID (i.e. a group of numbers that form a set to be added):
- If there's only one row -then move onto the reducer
- If there's 2 rows or more - then pass the 2 rows through the adder and hold rows 3+ till later
- Then pass the result of the adder on to the reducer
- By now you've taken the first 2 rows of any experiment and added and reduced them - now union back rows 3+ from above
- If there's more than 2 rows for any given experiment - then iterate, otherwise output
The adder:
The adder (the grey plus above) is super simple - it just wraps both sides in brackets and concatenates
The reducer
The exploder:
The Splitter: