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 2024 Day 13 (BaseA Style)

AlteryxCommunityTeam
Alteryx Community Team
Alteryx Community Team
Discussion thread for day 13 of the Advent of Code - https://adventofcode.com/2024/day/13
15 REPLIES 15
DataNath
17 - Castor
17 - Castor

Day 13 done and dusted! I've always struggled with Maths so did have to look up formulae etc, but converted this into BaseA myself. If nothing else this has been a great refresher/lesson in linear equations!

 

Spoiler
Day 13 - Workflow.png
leozhang2work
10 - Fireball
Spoiler
day 13.png

Initially thought finally a problem for Optimization tool, even the location optimizer macro. After some unnecessary fiddling, back to basic linear algebra 101 😂

cgoodman3
14 - Magnetar
14 - Magnetar

@leozhang2work here's how to solve it with the optimisation macro, which I will still count as BaseA as it's a tool installed with Designer 🙄

Spoiler
Part A: Took the brute force approach to solve the equations by generating the rows, but this approach is tool slow for part B
Part B: I knew I could solve it using the optimisation tool, I just need to work out how to shape the data so it would work for the inputs. I've always struggled to know how to do this as I've previously reverted to using manual inputs into the tool but find this is higher risk of typos, plus for today I needed to find a method which would wrap this inside a batch macro.

Screenshot 2024-12-13 111648.png

 

Chris
Check out my collaboration with fellow ACE Joshua Burkhow at AlterTricks.com
Goddenra
8 - Asteroid

If only I'd taken a step back at the start and realised it's just maths!




mark-spain
8 - Asteroid

It took me a while to realise how easy this one actually is 😂

After generating 100 rows each for the button a presses and 100 rows for the button b presses and trying each combination to see which ones worked. I realised that these linear equations can be made much simpler to remove the reliance on Generate Rows. 

Spoiler
AoC 2024 Day 13.png

 


I kept the Generate Rows method in for Part 1, creating a Bool flag to tell me which equations resulted in correct answers: 
([A_x] * a) + ([B_x] * b) = [P_x] && ([A_y] * a) + ([B_y] * [b]) = [P_y]​

and then filtered out where this was false, before calculating the tokens and aggregating: 

[a] * 3 + [b] * 1


For Part 2, I went off in completely the wrong way when I tried to make the X equation and Y equation equal when I multiplied the A and B coordinates by the Prize coordinates. So I got the pen and paper out and worked it out properly and adjusted my formulae. 

// solving for a, multiply prize by b
p_diff = abs(([P_x] * [B_y]) - ([P_y] * [B_x]))

// solving for a, multiply a by b
a_diff = abs(([A_x] * [B_y]) - ([A_y] * [B_x]))

// validate the modulo
Valid Multiple = MOD([p_diff], [a_diff]) = 0

// Calculate a
IF [Valid Multiple] 
THEN [p_diff] / [a_diff]
ELSE NULL()
ENDIF

// Calculate b - watch out for edge cases that don't go into the remainder an equal number of times
IF !IsNull([a]) && MOD(([P_x] - ([A_x] * a)), [B_x]) = 0
THEN ([P_x] - ([A_x] * a)) / [B_x]
ELSE NULL()
ENDIF
Yoshiro_Fujimori
15 - Aurora

My solution.

 

Spoiler
Workflow
workflow.png
Formula
[A] = ([M22]*[X] - [M12]*[Y]) / ([M11]*[M22] - [M12]*[M21])
[B] = ([M11]*[Y] - [M21]*[X]) / ([M11]*[M22] - [M12]*[M21])

 

 

Labels