side, and all four walls are mirrors. A laser sits in the bottom left corner, and the other corners hold sensors: the bottom right one is number 0, the top right one is 1, the top left one is 2.
The laser fires so that the beam first touches the right wall at height rise above sensor 0. From there it keeps bouncing off the walls until it runs into a corner.
Return the number of the sensor the beam hits first. You may assume it always reaches some sensor.side=4, rise=1 → 2
The beam rises by 1 on every crossing between the left and right walls. It reaches height 4 after four crossings, which puts it back at the left wall, in corner 2.
side=5, rise=2 → 0
After five crossings the beam is at the right wall, and the total rise of 10 is twice the room height, so it is at the bottom, in corner 0.
side=3, rise=3 → 1
The beam runs straight along the diagonal and hits the top right corner 1 at once.
side=4, rise=1
2
Run checks the first 3 tests in your browser. Submit checks all 87 tests on the server, hidden ones included.