Php solves Joseph's ring

Source: Internet
Author: User
: 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.

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.