3v4l.org

run code in 300+ PHP versions simultaneously
<?php $assertions = [ 1 => 1, 4 => 4, 5 => 5, 6 => 4, 8 => 2, 9 => 1, 10 => 2, 11 => 3, 12 => 4, 13 => 5, 14 => 4, 15 => 3, 16 => 2, 17 => 1, 18 => 2, 19 => 3, 20 => 4, 21 => 5, 22 => 4, ]; /** * @param positive-int $count * @return positive-int */ function countFingerPingPong(int $count): int { $remainder = max(1, $count%5); $directionCircle = floor($count/5); var_dump($remainder); var_dump($directionCircle); return $directionCircle%2 === 0 ? $directionCircle -1 : 4 - $remainder; } foreach($assertions as $count => $assert) { if (countFingerPingPong($count) !== $assert) { throw new Exeption('Assesstions failed.'); } }

preferences:
15.83 ms | 402 KiB | 5 Q