Elastic collisions between blocks

APL (Dyalog Classic), 18 16 bytes

¯1+⌈○÷¯3○.5*⍨⎕÷⎕

Try it online!

rendered as the equivalent {¯1+⌈○÷¯3○.5*⍨⍵÷⍺} in the tio link, to facilitate testing; means evaluated input; and are the arguments to an anonymous function

$$\left\lceil\frac\pi{\textrm{arctg}\sqrt\frac ba}\right\rceil-1$$

(that's the formula from the video. i recommend watching it. it's well explained and the animations are great for building intuition.)


Jelly, 10 9 bytes

My first Jelly submission :')

÷½ÆṬØP÷Ċ’

-1 byte thanks to Mr.Xcoder

Uses the formula as in the video. Receives the input flipped; OP gave permission. It probably has room for further golfing, so be sure to give me feedback!

÷½        divide b by a and take square root
  ÆṬ      take the ArcTan of that; then
      ÷   divide
    ØP    pi
          by the number we had.
       Ċ  Round up
        ’ and subtract one

Try it online


JavaScript (ES7),  41  39 bytes

Takes input as (a)(b).

a=>b=>3.14159265/Math.atan((b/a)**.5)|0

Try it online!

How?

Instead of using a ceil function and subtracting \$1\$, we deliberately use a slightly underestimated approximation of \$\pi\$ and floor the result with a bitwise OR.

For \$a,b\le 10000\$, it was empirically proven to give the same results as this safer 44-byte version:

with(Math)f=a=>b=>ceil(PI/atan((b/a)**.5))-1

Try it online!