[Community Puzzle] Snooker Ball Collision

Coding Games and Programming Challenges to Code Better

Send your feedback or ask for help here!

Created by @Loufouh,validated by @WildSmilodon and @Pukunya.
If you have any issues, feel free to ping them.

@Loufouh
Great idea, very interesting to (re-)learn about physics and collisions.

There are two big issues though, which are making this problem not as enjoyable as it could be: trailing zeros (use formatted strings, not rounding) and the approximate stopping position (rather than the exact one – for testcase #2, your code does not give the correct answer).
These have already been raised in the contribution page (in particular, see comments from Niako, Lanfeust and GeekNbOne). Could you please address them, as it would make the puzzle much better/more enjoyable for people to solve?

1 Like

Hi @Loufouh , @WildSmilodon , @Pukunya ,

I can pass all test but the last one and i dont know why.
According to my results, the collision appears later on (because my ‘Y’ coordinate for the first ball is greater than the expected one.)

found:
1.35 0.56
expected :
1.34 0.35

moreover, i modelized the friction force from 2 differents manner :
one according to this :

and one according to this :

can someone explain me why we use one instead of the other ?

Thanks,
Regards

Hi,
the theory upon, which the puzzle is set is explained here:
https://ravnik.eu/billiards-ball-collision/

The main (and from the physics point of view incorrect) assumption we make is to model the acceleration to be proportional to velocity. For such a model, you get very simple expressions for the movement and velocity of both balls.

In case you care about the actual physics, you should take into account air resistance and rolling friction. Both of these phenomena are difficult to model accurately.

Hope this helps!

thank you very much for the clarification.
I based my approched on something completly different. Because in my case i tried to respect both conservation of momentum and energy.
v1+v2 = v1’ + v2’
v1+v1’ = v2 + v2’

as mass are equal, when colision occurs v1 stop, to conserve momentum.
Maybe those type of “simplification”/“consideration”/“hypothesis” should be added to the puzzle description?!

Hi @WildSmilodon,

I apologize for reaching out again.

My code now passes all tests and validations except for the 4th one, which checks for horizontal movement. I’ve implemented safety guards such as valid domains for square root and logarithmic functions, as well as ensuring that collision times are positive. However, I’m still unable to identify the reason why it fails the horizontal validator.

I’ve conducted tests on horizontal movement with positive values for vx (test 4 : horizontal mouvement). In this scenario, a no-collision condition is expected, and the results appear correct—the static ball remains stationary, and only the x-coordinate of the moving ball is updated according to the formula for a no-collision scenario.

Without a trace of my results, I’m having difficulty pinpointing the issue. It might be a formatting problem, but without more information, I cannot determine the exact cause.

Your equation for conservation of energy should have velocity squared. Also, this does not apply here, as we consider friction, some of the energy is lost.

Maybe its an rounding issue.
The solution implemented by the author @Loufouh is not rigorous. If I remember correctly, he assumes the ball to be stopped when velocity is less than 1/1000.

Proper solution is obtained when taking the limit to infinite time, as I did on my web site.

@Loufouh, as the author of the puzzle, please respond and verify.