Personal summary of the monkey selected the King's Code, attached a note, for beginners will be very helpful, because I learned this time, understand Leng spent two or three hours, only to understand! Of course the code is ever changing! Before also saw a more concise, 5-6 lines on the written out, this varies from person to man, beginners still have to step by step!
2015 8.24 0:46
1 functiongetking($m,$n){2$arr=Array();//define an array for storing monkeys;3$a="a";//define the monkey number;4 for($i=0;$i<$m;$i++){//Start looping to each monkey by attaching a number;5$arr[] =$a++;//Loops A to M (gives the number of monkeys);6}78$i=0;//define a variable to be counted;9 while(Count ($arr) >1){//Get the number of monkeys, as long as the monkeys not less than 1 have been circulatingTenif($i%$n==0){//reported to the number of N to take the remainder (the number of sets, reported a few on a few to take the remainder of 0, then the monkey was proposed game) Oneunset($arr[$i]);//Delete an array element with a remainder of zero A}Else{ -$arr[] =$arr[$i];//If the array element is deleted if it is 0 , it is added to the end of the queue, and the next round continues to count, -unset($arr[$i]);//Delete the array element that you just added, which is abstract: the number of required numbers such as 5, 1 2 3, 4th-bit monkeys are not reported, then add -}//1 2 3 4 for the end of the squad, the lower round continues, while the 5th-bit monkey reported 5, was presented the game, the 6th-bit monkeys from 1, repeated so, -$i++; -} +return$arr; -} +Print_r (Getking ( -,5));
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The above introduces the PHP monkey choice King Popular understanding, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.