Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.

General Discussions

Discuss any topics that are not product-specific here.

Advent of Code 2022 Day 21 (BaseA Style)

AlteryxCommunityTeam
Alteryx Community Team
Alteryx Community Team
Discussion thread for day 21 of the Advent of Code - https://adventofcode.com/2022/day/21
7 REPLIES 7
mmontgomery
11 - Bolide
11 - Bolide

P1 not so bad. I tried to brute force P2 but figured i'd guess and check numbers one at a time to find the relationship between values

 

Spoiler
P1 was just writing to a numbers file then union results with each output then filter on root
P2 was doing a replace on humn's value by hardcoding some numbers into an adjusted macro to spit out the results. I wrote down input/output and figured out a relationship then kept manually replacing til I got it. Took about 30 minutes of trial/error

mmontgomery_0-1671642545605.pngmmontgomery_1-1671642640376.pngmmontgomery_3-1671642740958.png

 

 

 

 

DataNath
17 - Castor
17 - Castor

Day 21 done! Really enjoyed today. Working back from the root and building out the solver was very fun!

 

Spoiler
Workflow:

DataNath_0-1671660305835.png

 

Macro 1 - LookupBuilder - Iterates through expressions to work out all numbers:

DataNath_1-1671660354912.png

 

Macro 2 - DependencyTree - Works back from the route to find all numbers that depend on humn:

DataNath_2-1671660383915.png

 

Macro 3 - HumnSolver - Iterates backwards from the root, solving for humn:

DataNath_3-1671660458600.png

 Get the impression this was super overkill but hey ho - good macro practice!

AkimasaKajitani
17 - Castor
17 - Castor

In the first challenge, I tried to clear it by brute force, but could not.
When I reconsidered, I was able to create a concise logic.

 

Spoiler
AkimasaKajitani_3-1672380628400.png

 


 


Macro for Part1: Replace Macro
AkimasaKajitani_1-1672380210991.png

Part2: Replace Macro for Part 2: The condition for macro ending is different from part 1 macro.

AkimasaKajitani_4-1672380653857.png
Part2 : Reverse analysis Macro
The left and right sides are interchanged for analysis.
AkimasaKajitani_5-1672380670196.png

 




 

 

patrick_digan
17 - Castor
17 - Castor

Guess and Check for part2

Spoiler
patrick_digan_0-1672837405706.png



patrick_digan_1-1672837445706.png

 


 

clmc9601
13 - Pulsar
13 - Pulsar

Full workflow solutions here: https://github.com/clmc9601/Advent-of-Code-solutions/tree/main/2022%20Alteryx

 

Spoiler
I built a macro that solves algebraically. For part 2, I reversed the equation so the same macro would use the value from the first half to solve for humn instead of root.

workflowworkflowiterative macroiterative macro
PangHC
12 - Quasar
Spoiler
Pang_Hee_Choy_1-1673836715195.png

workflow


Part1:
split to data with number and equation.
build a macro to replace to equation, if the equation is solvable, add to iteration until everything solved!

Pang_Hee_Choy_2-1673836892752.png

part1 macro

Part2:
using method learn from neural network. add the error to the number with certain percentage.

e.g.  question is: find b, when 1000 - b = 100, rate is 10%
round 1: guess b = 300, then error is 600, multiply by rate, then add 60 (600*10%) to b
round 2 will be b = 360 (300+60), then error now will be 540, multiply by rate, then add 54 (540*10%) to b
etc. 

the b will slowly close to correct amount.
key is the rate can't too high as we do not know what calculation taking place.

Pang_Hee_Choy_3-1673837353044.png

part2 macro

SeanAdams
17 - Castor
17 - Castor

:-) well over a month late and Day 21 is done.

I really liked this one - a bit of tree-logic, a bit of dynamic execution, a bit of "solve for X" - what's not to love :-)

 

 

Spoiler
There are 3 parts to this challenge:
1) Parse: get it into a flat data structure - I chose to go with a flat table with NodeName; Operand1; Operand 2; and the Operator.
2) Resolve: This is kinda like a variable resolution process in compiler theory - you take the list of nodes and break them in to 2 groups
- Where we still have variables to replace with real values
- where we have an actual value (a literal)
Then you just loop, replacing variables with literal values until you run out - and that solves part 1
3) the solve-for-x
Part 2 is kinda interesting

if you have a massive binary tree - where buried somewhere in the tree is a value that you don't know - then you do get something else for free:
- One half of the tree will completely resolve to a literal number.
- The half with the unknown value (humn) will flatten out to a simple chain of linked formulae - because anything that doesn't have the humn in it's direct parentage will just resolve to a literal number

So to do part 2:
- Remove the Human node from the set (which had a literal value in the original)
- Run part 1 - then you get a chain of one side of the tree that still needs to be resolved - all simple formulae with one known value and one unknown value
- Do a "Solve for X".     for example - if you have a situation where XX = ?? + YY - then you can convert this to solve for ?? by saying that ?? = XX - YY.
        - this essentially turns the chain that was left inside-out so that humn becomes the root
- Then just run your Part 1 solver again 

SeanAdams_0-1675103940240.png

The Tree Solver:

SeanAdams_1-1675104210686.png

The Solve for X:

SeanAdams_2-1675104934625.png

 



Labels