We have extended our Early Bird Tickets for Inspire 2023! Discounted pricing goes until February 24th. Save your spot!

alteryx Community

# General Discussions

Discuss any topics that are not product-specific here.

## Advent of Code 2022 Day 21 (BaseA Style)

Alteryx Community Team
Discussion thread for day 21 of the Advent of Code - https://adventofcode.com/2022/day/21
7 REPLIES 7
8 - Asteroid

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

16 - Nebula

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

Spoiler
Workflow:

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

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

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

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

16 - Nebula

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

Macro for Part1: Replace Macro

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

Part2 : Reverse analysis Macro
The left and right sides are interchanged for analysis.

17 - Castor

Guess and Check for part2

Spoiler

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.

workflowiterative macro
10 - Fireball
Spoiler

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!

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.

part2 macro

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

The Tree Solver:

The Solve for X:

Labels