: This article mainly introduces php solutions for Joseph's ring. if you are interested in PHP tutorials, please refer to it.
# N monkeys numbered 1 to n are enclosed in a circle. the number of monkeys numbered 1 to n starts from 1, and the number of monkeys numbered k + 1 returns 2, monkey k + 2 reported 3 ........ report to m, and report the number from 1 again. report to m and repeat the cycle to find the number of the last monkey. Function myf ($ array, $ m, $ n, $ k) {$ mark = 0; $ a = $ m; $ m = $ m + $ K-1; while (sizeof ($ array) {$ mark ++; $ out = array_shift ($ array); if ($ mark ==$ m) {if (sizeof ($ array) = 0) {echo $ out, 'is left
';} Else {$ m = $ a; echo $ out,' out
'; $ Mark = 0 ;}} else {$ array [] = $ out ;}} myf (range (1, 5), 3, 5, 2); # test, monkeys numbered 1 to 5 report the number from 1 to 3 from 2?>
The above introduces php's solution to Joseph's ring, including some content, and hopes to help friends who are interested in PHP tutorials.