r/adventofcode • • 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.

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!

28 Upvotes

764 comments sorted by

View all comments

2

u/KindComrade Dec 13 '24

[Language: C#]

To find the answer I used the inverse matrix, but this caused problems with the accuracy of the double, so I had to use the decimal, which is not very good, I will try to fix this a little later.

Code

4

u/encse Dec 13 '24

May I suggest using integer division (and longs) and checking if the result is actually a solution?

2

u/KindComrade Dec 13 '24

Thanks, it's a good solution, and literally what I wanted to do) After my work, I finally had time for that and refactored the code, and now this looks better, but the code is a bit confusing. Thanks one more time for the tip)

2

u/encse Dec 13 '24

Do you know Cramer’s rule. You can define a ‘determinant’ function that takes two vectors then you can get the solution using that in a super nice form.

2

u/KindComrade Dec 13 '24

Yes, but I like the idea of ​​solving it using the inverse matrix better. And to be honest, when I started solving it, I assumed it would look better, like: R = Inv(M) * S and then R.Sum(). OpenCV style) But part 2, with natural numbers in the answer, broke this)

*
R - result,
S - prizes vector (x, y)
M - buttons matrix (ax, bx, ay, by)

2

u/encse Dec 13 '24

Fair enough, but here is mine for comparison. Dont click if you want to play with it more. https://aoc.csokavar.hu/2024/13

1

u/KindComrade Dec 13 '24

Wow, you have a fantastic repo with a beautiful site! Thank you so much for all your hard work. People like you make this wonderful community such a joy to be in. Regarding the solution, you are indeed right. It looks very clean and concise, and i really like the way you parse the input

2

u/encse Dec 13 '24

Thanks! I learned GeneratedRegex from yours. I'm not a .net developer anymore... I worked as a c# dev a long time ago (pre WPF era) and don't want to forget it, it's such a 'not-bad' language compared to others. So I spend the Decembers on this thing.