PHP solve Joseph Ring

Source: Internet
Author: User
 
 #编号1到n的n个猴子围成一圈, from the K monkey began to count off 1, k+1 Monkey newspaper 2,k+2 3 ... Check in M out of the remaining re-count from 1, report m out, repeated circulation, beg the last remaining monkey number. 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, ' eventually left
'; } else{ $m = $a; echo $out, ' exit
'; $mark =0; } } else{ $array []= $out;}} } MYF (Range (1, 5), 3,5,2); #测试一下, numbers 1 to 5 of monkeys, starting from 2nd by 1 count, reporting 3 out of the?>

The above describes the PHP solution Joseph Ring, including the aspects of the content, I hope the PHP tutorial interested in a friend helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.