General Discussions

Discuss a wide range of topics! Questions about the Alteryx Platform should be directed to the appropriate Product discussion forum.

Advent of Code 2021 Day 18 (BaseA Style)

jdunkerley79
16 - Nebula
16 - Nebula

Discussion thread for day 18 of the Advent of Code - https://adventofcode.com/2021/day/18

5 REPLIES 5
clmc9601
12 - Quasar

Surely there's a better way than so many multi-row formulas and nested macros

Spoiler
WorkflowWorkflowFirst macro's nested internal macroFirst macro's nested internal macro
patrick_digan
16 - Nebula
16 - Nebula

My code was super slow and super ugly, but I got the right answers

Spoiler
I parsed it very manually. Then part 2 was going to take well over an hour, so I reconfigured my macro and got it down to a minute. 
dsmdavid
11 - Bolide

Well, it works. eventually.

Spoiler
dsmdavid_0-1640000010946.png

messy chained and ugly macros. Takes forever to run (several hours). Will certainly look into the other solutions for ideas 🙂

 

 

 

https://github.com/dsmdavid/AdventCode2021

SeanAdams
17 - Castor
17 - Castor

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!

 

Spoiler
Progressive breakdown of the solution:

Top level:
- Take the input from the web
- Then make all the relevant combinations 
- Then pass it through the adder (see below) 
- Then the magnitude calculator
- Then pick the highest

SeanAdams_0-1640397984597.png

 

Magnitude Calculator:
This is an iterative macro - essentially the algo is:
- Use Regex to find a leaf-level pair (e.g. something like [1,2] with no embedded pairs within it)
- Calculate the magnitude of that pair
- Replace the pair with that value
- ... and then iterate
do this until you're left with a single number (i.e. no brackets)

SeanAdams_1-1640398113653.png


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

SeanAdams_2-1640398370919.png

 



The adder:
The adder (the grey plus above) is super simple - it just wraps both sides in brackets and concatenates

SeanAdams_3-1640398435089.png

 

The reducer
The reducer is a bit more complex:
- It calls the checker (the question mark) to see if any explosions or splits are needed
- If explosions are needed - this takes precedence
- if no exposions needed - then do any needed splits
- if no explosions or splits needed - then send to outputs


SeanAdams_4-1640398477859.png

 

The exploder:
The exploder is the most complex piece.  The algo is:
- Use a set of multi-rows to figure out which pair to explode
- You then add the values to the first natural number in the pre & post sets
- and then concatenate all of these back together.
This one took me a while to get working cleanly - specifically the logic to split above and below the pair to be exploded

SeanAdams_5-1640398706716.png

 

The Splitter:
This is the final piece.    I had to rebuild this becase the first time I built it, it split ALL values over 10, but a close reading of the problem description says that you should only do the left-most one, and then go back and check for explosions.
The algo is similar to the exploder:
- Use a multi-row to find the value to be split
- Replace this row with a split pair
- join it all back together again

SeanAdams_6-1640399026298.png

 





 

 

Pang_Hee_Choy
10 - Fireball
Spoiler
part 1 almost same idea. hence i continue to part 2.

for part 2, we can change the macro in part 1 to proceed the data by grouping RecordID. It will slow down part 1 result, but it speed up part 2.
mine is 3:31 minutes.

Pang_Hee_Choy_0-1641807009013.png