0

私の友人は、円の中に人が座っているヨセフス問題について教えてくれました。41番人1は刀を持っており、右隣の人を殺し、次の人に刀を渡す。これは、生き残った人が1人になるまで続きます。私はPythonでこの解決策を思いつきました:

print('''There are n people in the circle. You give the knife to one of 
       them, he stabs person on the right and
       gives the knife to the next person. What will be the number of whoever
       will be left alive?''')

pplList = []
numOfPeople = int(input('How many people are there in the circle?'))


for i in range(1, (numOfPeople + 1)):
    pplList.append(i)
print(pplList)

while len(pplList) > 1:
    for i in pplList:
        if i % 2 == 0:
            del pplList[::i]
    print(f'The number of person which survived is {pplList[0]+1}')
    break

しかし、それは人にしか機能しません42。どうすればよいですか、またはコードをどのように変更すれば、たとえば100, 1000サークル内のより多くの人が機能するようになりますか?

Josephusの問題を調べて、さまざまな解決策を見てきましたが、少し調整した後に私の答えが正しいのか、それとも最初から始めるべきなのか知りたいです。

4

2 に答える 2