Sign up at app.codecrafters.io/join?via=hyper-neutrino and try out Codecrafters today! You can get a taste of their many learning streams and try out their beta courses all completely for free (no credit card needed), and when you go to sign up, you'll get 40% off at checkout and support the channel! Thank you for watching :) (Codecrafters has not sponsored this video directly and they did not have the opportunity to review any of this video, including the promotional segment.)
Thank you for taking the time and efford to actually explain why you do as you do. Learned a lot of Python from your series here! And saw even more that made little sense yet.
I really appreciate the very educational side of your videos. they serve me both in my development in Python, and in the approach to analysis and understanding of subjects. THANKS
The original equations in part 2 are nonlinear. But if you subtract the equations for two different hailstones from each other, you get new equations that are linear in the unknowns ! This makes it possible to solve the problem using a 6*6 linear equation system. Or actually you can realise that you can solve it as one 4*4 system and another 2*2 system. Code for part 2 runs in microseconds. But took longer time to figure out...
Thanks a lot. You helped me on 3 or 4 puzzles this year, where I probably could not have finished part 2 on my own. I am still struggling to understand how for this one part 2 has a unique solution. If (p, v) is a solution (with integer coordinates), shouldn't (p + n*v, v) also be a solution for arbitrary integers n, or at least for all integer n less than some value. There was no restriction, that the first hailstone has to be hit at t=0 or t=1.
Using only the first three lines of the input data you have enough information to solve the unknowns. The rest is just more data that is constrained without removing any degrees of freedom. We basically have a massively overdetermined system of equations. If we take the first three lines of input data we have 9 unknowns (px,py,pz,vx,vy,vz,t0,t1,t2) and 9 equations. If you do what you propose and add an arbitrary multiple of V to P you change the time of your propagating line and it will miss the hailstones because it will always be a fixed time period too late or too early to hit the hailstones. Remember that for every time tick both your line and all hailstones move.
If you move the rock back then it will not meet the hailstone at the right time. The key component of this is that for P2, we check if they actually collide, unlike P1 where we just check if the paths intersect.
there's 6 unknowns (xr, yr, zr, vxr, vyr, vzr) and far more than 6 equations if you loop through all the hailstones. So don't you just need to go through the first 3 hailstones (which gives you 6 equations in 6 unknowns) and solve the resulting 6 equations, and that solution must be the solution for the whole thing since it's overconstrained? I did this with sympy and it gave the correct answer. Or is this a coincidence and there something I'm missing?
I'm also wondering about this, because I needed 4 hailstones => 8 equations to get the correct answer. Some reason it didn't work with 3 hailstones => 6 equations.
The 6 equations for 6 unknowns requires that the equations are all linearly independent, which isn't necessarily the case (I haven't checked if they are or not for my input).
@@toddchaney2454 As @hyper-neutrino said when replying to my comment above: 6 equations only work if all 6 are linearly independent (which may not be the case) and you may need more than 6 equations to have at least 6 linearly independent ones.
Sign up at app.codecrafters.io/join?via=hyper-neutrino and try out Codecrafters today! You can get a taste of their many learning streams and try out their beta courses all completely for free (no credit card needed), and when you go to sign up, you'll get 40% off at checkout and support the channel! Thank you for watching :)
(Codecrafters has not sponsored this video directly and they did not have the opportunity to review any of this video, including the promotional segment.)
thank you for your to-the-point explanation of part 2
Thank you for taking the time and efford to actually explain why you do as you do. Learned a lot of Python from your series here! And saw even more that made little sense yet.
I really appreciate the very educational side of your videos. they serve me both in my development in Python, and in the approach to analysis and understanding of subjects. THANKS
Great work! Very helpful
Hey, you could also add integer constraints to symbols. That way, only integer solutions will be returned
The original equations in part 2 are nonlinear. But if you subtract the equations for two different hailstones from each other, you get new equations that are linear in the unknowns ! This makes it possible to solve the problem using a 6*6 linear equation system. Or actually you can realise that you can solve it as one 4*4 system and another 2*2 system. Code for part 2 runs in microseconds. But took longer time to figure out...
Can you present how you solved this algebraically?
I was wondering if there was a someone that would not use a solver. So I felt good haha. But seems we all did the same.
Thanks a lot. You helped me on 3 or 4 puzzles this year, where I probably could not have finished part 2 on my own.
I am still struggling to understand how for this one part 2 has a unique solution.
If (p, v) is a solution (with integer coordinates), shouldn't (p + n*v, v) also be a solution for arbitrary integers n, or at least for all integer n less than some value. There was no restriction, that the first hailstone has to be hit at t=0 or t=1.
Using only the first three lines of the input data you have enough information to solve the unknowns. The rest is just more data that is constrained without removing any degrees of freedom. We basically have a massively overdetermined system of equations. If we take the first three lines of input data we have 9 unknowns (px,py,pz,vx,vy,vz,t0,t1,t2) and 9 equations. If you do what you propose and add an arbitrary multiple of V to P you change the time of your propagating line and it will miss the hailstones because it will always be a fixed time period too late or too early to hit the hailstones. Remember that for every time tick both your line and all hailstones move.
If you move the rock back then it will not meet the hailstone at the right time. The key component of this is that for P2, we check if they actually collide, unlike P1 where we just check if the paths intersect.
@@mcg6762 Thanks. Yes, I forgot that now we actually hit the hailstones, not just their trajectory.
there's 6 unknowns (xr, yr, zr, vxr, vyr, vzr) and far more than 6 equations if you loop through all the hailstones. So don't you just need to go through the first 3 hailstones (which gives you 6 equations in 6 unknowns) and solve the resulting 6 equations, and that solution must be the solution for the whole thing since it's overconstrained? I did this with sympy and it gave the correct answer. Or is this a coincidence and there something I'm missing?
I'm also wondering about this, because I needed 4 hailstones => 8 equations to get the correct answer. Some reason it didn't work with 3 hailstones => 6 equations.
The 6 equations for 6 unknowns requires that the equations are all linearly independent, which isn't necessarily the case (I haven't checked if they are or not for my input).
@@hyper-neutrino Oh right makes sense
@@toddchaney2454 As @hyper-neutrino said when replying to my comment above: 6 equations only work if all 6 are linearly independent (which may not be the case) and you may need more than 6 equations to have at least 6 linearly independent ones.
it just happened to be the case for my input that the first 6 were linearly independent