[M💙 Challenge] Bouncing Ball Physics 🏀〽 | Sololearn: Learn to code for FREE!

+30

[M💙 Challenge] Bouncing Ball Physics 🏀〽

Monday Blue 💙 Challenge Series #10 Let's get some exercise this week! This time we will simulate a bouncing ball in SoloLand and illustrate its moving path until it become idle due to gravity. 💼 TASK Write a program to accept an integer which represents the ball height unit (above the ground) and perform a free fall with gravity of 1 unit. In addition, we assume the ball losts its energy due to gravity when it hits the floor. For example, Ball height (Input): 3 Output: o_________ _o___o____ __o_o_o_o_ ___o___o_o Explanation: (P) 3 2 1 [0] 1 2 1 [0] 1 [0] (K) 0 1 2 [2] 1 0 1 [1] 0 [0] Above shows the relationship between (P)otential energy and (K)inetic energy of the ball. The square bracket indicates the ball hit the floor and going to rebounce. In this case, we will deduct 1 unit from the kinetic energy to indicate the energy loss otherwise the ball will bounce forever. 😉 🔧 TEST CASE Ball height: 2 Output: o____ _o_o_ __o_o Ball height: 1 Output: o_ _o ➕ EXTRA Determine the unit time needed for the ball to reach an idle state for a given height. ❤ BONUS Clear-cut and optimized approach is encouraged. 👍 SPECIAL MENTION https://code.sololearn.com/WgnwdOv2XpDd/?ref=app https://code.sololearn.com/c61h77fAst30/?ref=app Happy Coding!!! 😁💻

11/27/2017 5:15:27 AM

Zephyr Koo

45 Answers

New Answer

+13

My try https://code.sololearn.com/cp30g7bRzvb3/?ref=app

+13

@blackcat1111 Thanks for your input! Apologize as I'm not fluent in Physics and worry if too much of technical terms will scare them away. 😂 Anyway please feel free to highlight it when you provide the solution later. 😉

+12

https://code.sololearn.com/cDPHOAPXCSWJ/?ref=app

+12

It seems both of you have the same mindset! No hard feeling please, we are here to have fun and learn from each other! 😉

+11

@Vadim Good insight! In fact the illustration above shows the ball position at different time frame and each column represents a unit time. Combine every frame together and you'll get the parabola. 😉 Edit: Perhaps a parabola-like straight line?

+10

@blackcat1111 Wow that was real FAST! Thanks for your submission! 😄

+10

very nice challenge!

+10

@Hamid..why copy my style..? last part in my code. ..very Claver you are.. first time you did not add graph @kinshuk..may be know it

+10

I asked myself,"why did I post 7 minutes later of you"?

+10

+10

Thanks everyone for your participation! I feel guilty this time as there are a few nice solutions but I can select one from it. Please be reminded that it doesn't mean your solution is bad if your solution was not selected. I'll try to pick some unique solutions and put it @ SPECIAL MENTION and hopefully your hard work will be appreciated. 😉 I hope you all enjoy and let's move on to the next challenge! ❤ https://www.sololearn.com/Discuss/885383/?ref=app

+9

@Kinshuk Vasisht Nope. Just display the graph will do and the energy levels are optional as it's just for better understanding. 😉

+9

@Vadim Yes you've done a pretty good job! 😉👍

+7

hi, here's my try.. 🐍 very nice challenge!! 😀 https://code.sololearn.com/culAWXSyZY1N/?ref=app

+6

My Submission : Edit - Now with a function to display the time taken by the ball to come at rest. https://code.sololearn.com/c61h77fAst30/#cpp

+6

Made me scratch my brain hard 😧 https://code.sololearn.com/cko7zCbI8DL1/?ref=app

+5

Here! Just finished it 😉 https://code.sololearn.com/cR3H5Jr0NNJ2/?ref=app

+5

@Vadim Sukhotin It could be the graph of |v| against ∆t, where v is the velocity of the ball and t is each unit time, rounded off to the nearest unit, ignoring air resistance and drag force. (Taking upwards as the positive direction.) 🤔 OR... We could simply accept that there is only so much information a 2x2 matrix can convey. And it helps make the problem simpler (no one likes to differentiate quadratics and cubics in relation to the tangent of the displacement of the ball with regards to gravity... or at least I don't).😉

+4

Interesting challenge! I may do it later if I have time. (P.S. Isn't it "Gravitational Potential Energy" and not just "Potential Energy"? Sorry I have slight OCD about these things 😉)

+4

@Zephyr Koo So, in the code, are we to display the Energies as they are there in the graph or display a graph as well representing the ball? Output (if its a graph): o_________ _o___o____ __o_o_o_o_ ___o___o_o Output (if its the energy levels) : (U) 3 2 1 [0] 1 2 1 [0] 1 [0] (K) 0 1 2 [2] 1 0 1 [1] 0 [0] Or do we have to display both side by side?