The Joseph problem (sometimes also called the Josephus permutation, is a problem that appears in computer science and mathematics. In computer programming algorithms, similar problems are also called Joseph rings. Also known as the "lost handkerchief problem".)
A group of monkeys, all with numbers, stood in a circle, and those who counted to m were shot, and the rest continued counting. If this goes on and on, the remaining one will go crazy
Copy code The code is as follows:
function killMonkeys($monkeys, $m){
$k = $m;
while (count($monkeys)){
$k = $k - 1;
$monkey = array_shift($monkeys);
if ($k ) {
$monkeys[] = $monkey; & lt; br/& gt; "
$ k = $ m;
}
}
echo $ monkey." >$monkeys = range(0, 25);
unset($monkeys['0']);
$m = 5;
killMonkeys($monkeys, $m);
http://www.bkjia.com/PHPjc/751512.htmlwww.bkjia.com
truehttp: //www.bkjia.com/PHPjc/751512.htmlTechArticleThe Joseph problem (sometimes also called the Josephus permutation) is a problem that arises in computer science and mathematics. In In computer programming algorithms, similar problems are also called Joseph rings....