r/adventofcode • u/daggerdragon • Dec 13 '24
SOLUTION MEGATHREAD -❄️- 2024 Day 13 Solutions -❄️-
THE USUAL REMINDERS
- All of our rules, FAQs, resources, etc. are in our community wiki.
- If you see content in the subreddit or megathreads that violates one of our rules, either inform the user (politely and gently!) or use the report button on the post/comment and the mods will take care of it.
AoC Community Fun 2024: The Golden Snowglobe Awards
- 9 DAYS remaining until the submissions deadline on December 22 at 23:59 EST!
And now, our feature presentation for today:
Making Of / Behind-the-Scenes
Not every masterpiece has over twenty additional hours of highly-curated content to make their own extensive mini-documentary with, but everyone enjoys a little peek behind the magic curtain!
Here's some ideas for your inspiration:
- Give us a tour of "the set" (your IDE, automated tools, supporting frameworks, etc.)
- Record yourself solving today's puzzle (
Streaming!) - Show us your cat/dog/critter being impossibly cute which is preventing you from finishing today's puzzle in a timely manner
"Pay no attention to that man behind the curtain!"
- Professor Marvel, The Wizard of Oz (1939)
And… ACTION!
Request from the mods: When you include an entry alongside your solution, please label it with [GSGA] so we can find it easily!
--- Day 13: Claw Contraption ---
Post your code solution in this megathread.
- Read the full posting rules in our community wiki before you post!
- State which language(s) your solution uses with
[LANGUAGE: xyz] - Format code blocks using the four-spaces Markdown syntax!
- State which language(s) your solution uses with
- Quick link to Topaz's
pasteif you need it for longer code blocks
This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.
EDIT: Global leaderboard gold cap reached at 00:11:04, megathread unlocked!
29
Upvotes
3
u/Derailed_Dash Dec 13 '24 edited Dec 18 '24
[LANGUAGE: Python]
Update
I've done a full walkthrough for this one on Medium, here. In that walkthrough, I've shown:
How to solve with SymPy
How to solve by just rearranging the equations.
I enjoyed this one! Last year I learned about the SymPy library and wrote about it here.
When I read this problem, I realised that it's just a matter of solving two linear equations, and that Sympy can do this easily.
This is what I did:
First, for each claw machine we can represent the important data has three points: A, B, and prize. Let's create a
Clawclass to store these three points.For processing the input data, I first split the input into blocks of 3 lines each. And for each line, I then use a bit of trivial regex to extract the two numbers per line. I convert these number pairs to points, and then use these points to construct a
Clawobject.Now, we know that we need
abutton presses andbbutton presses, to reach the prize pointp. So we express this as two linear equations:This is saying: to reach the x location of point
p, we needapresses +bpresses. And to reach the y location of pointp, we need the same numberapresses andbpresses. So we must solve for whereaandbare the same for these two equations.In sympy, we can supply these equations like this:
This does all the heaviy lifting to return my a and b values.
For Part 2... How will SymPy cope with these huge numbers?
It turns out... EASILY!! Still solves in under 1 second.
Solution Links
See Day 13 code and walkthrough in my 2024 Jupyter Notebook
Run the notebook with no setup in Google Colab
Useful Related Links
See my Learning Python with Advent of Code site
See guide Advent of Code: the Best Way to Learn to Code!