Day 13 - Solutions
I was considering performing a tree search there (because of the limitation to 100 button presses), but decided to go with some algebra, which made part 2 trivial. https://github.com/erdos/advent-of-code/blob/master/2024/day13.clj
Yeah, I went this way too, as I expected something like +10000000000000 in Part 2 https://github.com/zelark/AoC/blob/master/src/zelark/aoc_2024/day_13.clj
Yeh I expected numbers to go up, but stupidly I was staring at it and thinking “I probably need to use least common multiplier in some way”, that wasted like half an hour
Yeah, me too, I was looking at the chinese remainder theorem before just writing down the two equations and sorting it out.
Maths are mathing
Math, eh? I got an intuition for part 2 playing around a bit in wolfram. I eventually figured out what to do to and then spent way way too much time implementing the trivial math. Wheee https://gitlab.com/maximoburrito/advent2024/-/blob/main/src/day13/main.cljI
Oh shoot I missed a simplification, the equation is correct but it could be simpler 😅
ratio? Oh yeah, I guess that exists... 🙂
Thank you to those of you who said to solve the simultaneous equations. I have no patience when the problems require knowing which mathematical things to do, but once I got that hint I was able to solve them myself. • Blog: https://github.com/abyala/advent-2024-clojure/blob/main/docs/day13.md • Code: https://github.com/abyala/advent-2024-clojure/blob/main/src/advent_2024_clojure/day13.clj
Algebra solution here: https://github.com/genmeblog/advent-of-code/blob/master/src/advent_of_code_2024/day13.clj
First part can be also solved by linear optimization (simplex), part 2 is problematic since it works on doubles not longs...
;; Button A: X+94, Y+34
;; Button B: X+22, Y+67
;; Prize: X=8400, Y=5400
(fastmath.optimization/linear-optimization [3 1 0] [[94 22] :eq 8400
[34 67] :eq 5400
[1 0] :leq 100
[0 1] :leq 100])
;; => [(80.0 40.00000000000001) 280.0]mine similar to others, required some googling as I already forgot about cramers technique https://github.com/vollcheck/aoc/blob/master/src/y24/day13.clj wrt misleading instructions, I wonder how Eric will try to deceive us in the following days
since part 1 I was wondering if logic programming would be suitable for that problem, will try to set up some PoC
uh, so I solved the system equations mod p for a bunch of ps and then used CRT to see if the solution converged to the expected x/y. looking online it seems like this was perhaps overkill. https://github.com/tildedave/advent-of-code/blob/main/src/advent2024/day13.clj
I’m glad todays was shorter as I really really need to study my lines. I’m playing Santa in a Christmas play. Dress rehearsal at 2! https://github.com/bhauman/adv2024/blob/main/src/adv2024/day13/sol.clj
started with this, knowing it would be no good for a part 2
ended up with this, which was shorter 🤦♂️
https://github.com/rjray/advent-2024-clojure/blob/master/src/advent_of_code/day13.clj Hammered out part 1 with brute-force to try to gain some time (I've had several days where I couldn't start the puzzles until hours after they unlocked). Part 2 would obviously need something that wasn't loop-based. After looking at it for some time, I realized that it looked like old linear algebra problems. Some googling and I found the WIkipedia page for Cramer's Rule and based my solution on that. For curiosity, I also ran part 1 through this code and dropped the run-time 91% over the brute-force. That said, the brute-force "quick" solution got me my first <1000 ranking for a part 1 finish.
Math ❤️
lucky there's no div-by-zero error in my case
Given it's basically the equation of two lines intersecting, I don't think it could be equal to zero unless the two were parallels? It's been a while since middle school.
Zach's code checks 0 and that reminds me it's possible.
Stolen from Reddit:
The Chief Historian is missing, and instead of actually helping the historians find them, 80% of the time you decide to do literally anything else.
Tasks where you actually help the historians: 3
1: Tech support
6: Mission impossible
7: Crossing that bridge when we came to it
Tasks that take the opportunity to help someone else in the area: 7
2: Helping a nuclear power plant
3: Tech support, again
4: Helping a child with their wordsearch
5: Tech support, AGAIN
9: Tech support, A G A I N
10: Reindeer mountaineering
12: Fencing (not the cool kind with swords)
Tasks to thwart your arch nemesis: 1
8: Thwarting the great chocolate heist
Tasks where you do literally nothing useful: 2
11: Watchin' rocks
13: Pressing buttons 42 trillion timesNot gonna let day 9 defeat us.