Joseph ring Python description

xiaoxiao2021-04-06  272

First of all, it is easier to understand. .

Original title:

The user inputs M, N value, and n individuals enclose a ring, starting from No. 0 people, numbers to M, that person exits the game until the last person seeks the last one of the people? (Joseph ring problem josephus)

DEF SOLVE (N, M): # Automatic meter list, start from 0 to N-1 list = range (n) m- = 1 k = m% n; while (len (list)> 1): DEL LIST [ K] k = (k m)% len (list) return list [0] # then a very beautiful algorithm DEF GAME (n, m): if n == 1: Winner = 0 else: pre_winner = game (N -1, m); Winner = (pre_winner m)% N retURN Winner;

转载请注明原文地址:https://www.9cbs.com/read-132336.html

New Post(0)