Discussion thread for day 13 of the Advent of Code - https://adventofcode.com/2024/day/13
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!
Initially thought finally a problem for Optimization tool, even the location optimizer macro. After some unnecessary fiddling, back to basic linear algebra 101 😂
@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 🙄
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.
([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
// 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
My solution.
really dusting off the cobwebs in my brain on the math for this one. thanks Khan Academy for the refresher!
Day 13. More in spoiler
Finally getting around to posting this today... took the optimization approach (without using the R tools) to part 1, and then got out the old pen and paper to do some quick math to sort out my formulas for part 2 so my computer wouldn't explode on me... We've passed the halfway mark... no going back now.