您的位置:首页 > 编程语言 > Python开发

用Python中的list分片方法解决约瑟夫环问题

2015-07-09 21:26 726 查看
def func(n):

    person = []

    for num in range(1, n + 1):

        person.append(num)

    tag = True

    while len(person) > 1:

        length = len(person)

        if tag:

            person = person[::2]

        else:

            person = person[1::2]

        if length % 2:

            tag = False

    print(person)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息