Advent of Code 2024 | Day 13 "Claw Contraption"

Поделиться
HTML-код
  • Опубликовано: 14 дек 2024

Комментарии •

  • @mattisovereighteen
    @mattisovereighteen День назад +7

    Great explanation of the math behind the correct answer, thank you for making it as not-scary as possible! Working to the same equation in 2 different ways really makes it seem less like "magic" too 🙏

  • @nonscopks2659
    @nonscopks2659 День назад +4

    Great video, very clear explanation

  • @faresattya9227
    @faresattya9227 День назад

    This is an amazing video!! I’ve spent all my Friday evening trying to over-engineer and over-optimise the solution to this problem but kept reaching a dead end. Thanks a lot for the explanation and the simplification.

  • @pmareke
    @pmareke День назад +3

    Nice explanation, thanks so much! I used sympy to solve the problem, but it's nice to understand the logic behind!

  • @georgevalentin9483
    @georgevalentin9483 День назад

    That was actually a great explanation! Watched it for part 2, then took a break for a few hours then tried to implement everything myself, worked like a breeze!

  • @eavdmeer
    @eavdmeer День назад +1

    This is a very straightforward system of 2 equations with 2 unknown. I used a small generic linear equation solver, linear-solve in NodeJS for both cases. Runs in under 2ms. The only thing to watch out for is rounding issues. You get super near to integer numbers that you need to accept as close enough

  • @rastislavsvoboda4363
    @rastislavsvoboda4363 День назад

    excellent explanation, thanks 🙏
    I solved it using sympy, remembering last year's hail problem
    it runs ~7s; your solution is instant ;-)
    # pa, pb is not price, but pushes
    def get_pushes2(ax, ay, bx, by, x, y):
    pa, pb = sympy.symbols("pa, pb")
    equations = [pa * ax + pb * bx - x, pa * ay + pb * by - y]
    sln = sympy.solve(equations)
    pushes_a, pushes_b = sln.values()
    if sympy.simplify(pushes_a).is_Integer and sympy.simplify(pushes_b).is_Integer:
    return True, pushes_a, pushes_b
    # not Integer solution
    return False, pushes_a, pushes_b

  • @flwi
    @flwi День назад

    Very nice explanation! Thanks for that. My linear algebra knowledge is quite rusty and I had some trouble with part2.

  • @lrisirl
    @lrisirl День назад

    banger part 2 explanation

  • @枯萎の花
    @枯萎の花 День назад +1

    Py is really good at math caculation. I solved the problem in javascript, and I needed to take care of the issue of decimal precision.

  • @TheTrienco
    @TheTrienco 19 часов назад

    You have no idea how hard I made my life by expecting some cases of a and b being co-linear and that there WOULD be multiple solutions. That's why I originally ruled out this approach. I should have been smart enough to check a and b and treat those cases separately, in case they happen (which they never did).

  • @TheFrogfather1
    @TheFrogfather1 День назад

    I used an algebraic solution from the start. Part 1 worked fine but I got the wrong answer on part 2 until you emphasised that there is only one solution to each pair of equations (which I should have known).
    My mistake was to eliminate non integer results by checking that button A was an integer, but not button B.
    Of course there are some results where A is an integer but B isn't because Eric is a sneaky fellow.

  • @hyperbolia-44031
    @hyperbolia-44031 День назад

    I solved this one using sympy, which helped a lot, but went back and rewrote it using actual general solutions for the intersection of lines

  • @Mazza7-g1w
    @Mazza7-g1w День назад

    I used Cramer's rule to find the solutions. The end result is similar, but it's way easier to work out the equations.

    • @mohamedyasser5285
      @mohamedyasser5285 День назад +1

      Same! The linear algebra approach is 10x easier than pure algebra and only a couple more LoC. Just need to make sure that both a, b are integers before accepting them as solutions.

  • @Levy957
    @Levy957 День назад

    I tried with PuLP but got only the part one, part two was wrong

  • @IanRay-m5c
    @IanRay-m5c 17 часов назад

    *Day 13 was a linear algebra problem the whole time...*

  • @filipfolkesson3865
    @filipfolkesson3865 День назад

    11:40 What do you mean it becomes harder? Isn't it impossible unless the prize point is on either slope and if it is just compare the cost of the buttons?

  • @yun6717
    @yun6717 День назад

    I solved it using Z3

  • @koushikm
    @koushikm День назад

    Great videos, always. Even when I managed to solve the problem, I learn something new every day when I watch your explanations. Why you leave exercises to the "reader" ? Reader of what ? the captions ? Are you reading too many text books ?

    • @hyper-neutrino
      @hyper-neutrino  День назад +2

      oh. yep you're exactly right xD i've seen that phrase too many times in textbooks

  • @iselein_sh
    @iselein_sh День назад

    Nice solution! When the denominator is 0, wouldn't it mean that the vectors of the A and B directions are the same direction? Then we would have to check if you could get to the prize in an integer multiple of A or B and then pick the cheaper viable option.

    • @hyper-neutrino
      @hyper-neutrino  19 часов назад +1

      yep. i go over this later in the video but deliberately chose not to handle this case because it would be a lot harder than the problem itself. the difficulty comes from the ability to mix A and B presses even if they're collinear due to only being able to press buttons an integer number of times so you'd have to solve diophantine equations i think

    • @iselein_sh
      @iselein_sh 12 часов назад

      @@hyper-neutrino Oh that's true. It wasn't obvious to me that it was possible to mix A and B presses even if they are collinear. I get it now.

  • @clementdato6328
    @clementdato6328 День назад

    5:21 There could be infinite solutions or no solution. If the determinant is 0 (which my inputs never are), there could be (1) no solution the three vectors are colinear or (2) infinite solutions which we would have needed to find the best natural number solution.

    • @hyper-neutrino
      @hyper-neutrino  19 часов назад

      yep. i go over this later in the video but deliberately chose not to handle this case because it would be a lot harder than the problem itself

  • @nice-vf4rj
    @nice-vf4rj День назад +2

    Great video, brilliant guy!

  • @cubernetes
    @cubernetes День назад

    Does it turn into a mixed integer linear diophantine equation problem when the denominator is zero?

    • @hyper-neutrino
      @hyper-neutrino  День назад

      yes, i believe so

    • @sghuisman
      @sghuisman День назад

      It also means that the movements button a and b do are collinear and effectively a Diophantine equation indeed.

  • @saatviksingh3590
    @saatviksingh3590 День назад

    2:57 what is open(0)?

    • @avataru_
      @avataru_ День назад

      It opens a file, in this case the file containing the puzzle input.

    • @hyper-neutrino
      @hyper-neutrino  День назад +1

      it opens file descriptor 0 which refers to STDIN. i use a utility to pipe my input file into the program as STDIN

    • @saatviksingh3590
      @saatviksingh3590 День назад

      @@hyper-neutrino ooh that is neat

    • @billeterk
      @billeterk День назад

      Does Python have something similar to Perl’s ? Works as file argument or stdin

  • @prajwalsrao8178
    @prajwalsrao8178 День назад +7

    A =[ax,bx;by, by]
    B=[p1,p2]
    x,y = np.linalg.solve(A,B)
    Thank me later😅