Answer the question
In order to leave comments, you need to log in
How to solve the Joseph problem?
def josephus1(ls, skip):
skip -= 1
idx = skip
while len(ls) > 1:
if idx+1 > len(ls):
idx %= len(ls)
print(ls.pop(idx),"выбывает")
idx = (idx + skip) % len(ls)
print(idx,"Это IDX")
print('survivor: ', ls[0])
def josephus2(ls, skip):
skip -= 1
dead_num = 0
while len(ls) > 1:
dead_num = (dead_num+skip) % len(ls)
print(ls.pop(dead_num),"выбывает")
print('survivor: ', ls[0])
n = int(input('Введите количество человек:'))
m = int(input('Сколько человек посчитать?:'))
list_people = [i for i in range(1, n + 1)]
print(list_people)
josephus(list_people, m)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question