Get the App
SLTechnology News&Howtos  ›  Development  › 

How to implement the algorithm of executing prisoners by php in solving Joseph problem

Shulou Source: shulou.com Published: 2022-06-03 19:45:53 09月29日 Update

This article mainly introduces how to implement the php Joseph problem solving algorithm for the execution of prisoners, the article introduces in great detail, has a certain reference value, interested friends must read it!

The specific analysis is as follows:

In ancient times, a judge wanted to sentence IV prisoners to death. He had an absurd law that made prisoners stand in a circle. From the beginning of the second person, every D person was pulled out to be executed, and then D was counted, and then pulled out for execution. Until the last one can be pardoned.

Function getNum ($n quotient m) {/ / is used to initialize all the numbers in the array $a = array (); / / traverses, and stores it into the array for ($iposi1 * * i1) {/ / if the item in the array is greater than 1, continue to loop out the element / / delete the rule for ($job1 * j

Tags: Prisoners arrays algorithms problems Joseph Joseph individuals content articles pulls absurdity values elements interests circles boys buddies pointers more death penalty Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi vpn MySQL OPPO Reno MariaDB