Elastic collisions between blocks

APL (Dyalog Classic), 18 16 bytes


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 :')


-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).


Try it online!


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:


Try it online!