# totalNum:猴子总数
# startNum:开始序号
# intervalNum:间隔数
def KingElect(totalNum, startNum, intervalNum):
monkeyList = []
out_order = 0 # 出列排序
current_index = 0 # 当前列表下标
if (totalNum < intervalNum):
return
monkeyId = startNum # 猴子初始排列
for i in range(1, totalNum + 1):
if monkeyId == totalNum + 1:
monkeyId = 1
monkeyList.append(monkeyId)
monkeyId += 1
# print(monkeyList, end='')
while (len(monkeyList) > 1):
out_order += 1
current_index += 1
if (current_index > len(monkeyList)):
current_index = 1
if (out_order == intervalNum):
intervalNum += 1
out_order = 0
print('--', monkeyList[current_index - 1], 'Out')
monkeyList.pop(current_index - 1)
print( end='')
current_index -= 1
print('--', monkeyList[0], 'Gain the elect')
if __name__ == '__main__':
KingElect(60, 1, 2)