鱼C论坛

 找回密码
 立即注册
查看: 2374|回复: 1

[学习笔记] python解决魔术师发牌问题

[复制链接]
发表于 2019-4-19 14:37:55 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
问题简介
https://jingyan.baidu.com/article/0aa223755363c688cc0d6485.html

python的数据类型里没找到单循环链表的 又不想自己写 就用现成的列表类型改了下
参数是牌的长度 默认13
def p1(num=13):
    list1 = [0]*num
    index = 0
    count = 1  # 翻牌次数
    while 0 in list1:
        if count == 1:
            list1[index] = count
            count += 1
            continue
        if count > 1:    
            for i in range(count):
                index += 1
                if index > len(list1)-1:
                    index -= len(list1)
                while list1[index] != 0:
                    index += 1
                    if index > len(list1)-1:
                        index -= len(list1)
            list1[index] = count
            count += 1
    return list1
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2019-4-19 15:36:15 | 显示全部楼层
确实不擅长搞这种烧脑的,没看你答案前我试着自己弄,。。。。。。。。。搞了30分钟才出来思路了
max = 13
list = []
while True:
    if len(list) == 0:
        list.append(max)
    elif len(list) == max:
        break
    else:
        temp = max - len(list)
        list.insert(0,temp)
        count = temp -1
        while count:
            list.insert(0,list.pop())
            count -= 1

print(list)
不想起变量名,用了内置的函数作为变量名
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-6-18 14:34

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表