Home  >  Article  >  Backend Development  >  PHP solution to Joseph ring example_PHP tutorial

PHP solution to Joseph ring example_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:34:29725browse

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....
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn