This article mainly introduced the PHP to solve the Joseph Ring example, need friends can refer to the following
The question of Joseph (sometimes referred to as Josephus substitution) is a problem that arises in computer science and mathematics. In computer programming algorithms, similar problems are called Joseph Rings. Also known as the "throw the handkerchief problem". Monkeys a group, all with the number, stood a circle, count to M of the shot, the rest of the next number. So reciprocating, the rest of the dead is crazy. The code is as follows: <?php function Killmonkeys ($monkeys, $m) {$k = $m; while (count ($monkeys)) {$k = $k-1; $monkey = Array_shift ($monkeys); if ($k) {$monkeys [] = $monkey; else {echo "<font color= ' Red ' >". $monkey. "The </font> monkey is dead!" <br/> "; $k = $m; } Echo $monkey. "Number Monkey Spartan"; $monkeys = Range (0, 25); unset ($monkeys [' 0 ']); $m = 5; Killmonkeys ($monkeys, $m);