Story:
Joseph's question (Josephus problem) is said to have been the story of a famous Jewish historian Josephus: After the Romans occupied Chotapat, 39 Jews and Josephus and his friends hid in a hole, and 39 Jews decided that they would rather die than be enemies. So decided a suicide way, 41 people into a circle, from the 1th person began to count, each count to the 3rd person must commit suicide, and then again from the next re-count, until everyone killed himself.
However, Josephus and his friends did not want to follow, Josephus to his friends to pretend to obey, he put friends and himself in the 16th and 31st position, so escaped the game of death.
Original question:
User input M,n value, n person in a ring, starting from No. 0 number of people, count to M, that person quit the game until the last person
What's the last one left?
(Joseph Ring question Josephus)
First of all, it's easier to read.
Python code
- def Josephus (n,m):
- #自动身成列表, starting from 0 to n-1
- People = List (range (n))
- M-=1
- k=m%n;
- while (Len (People) >1):
- Del List[k]
- k= (k+m)% len (people)
- return people [0]
To tell the truth, the feeling is still because Python data structure is powerful, List del drop auto-complement, other languages estimated to be more laborious
Python solve Joseph ring problem