python求n的倍数_Python计算掷骰子数和数倍数

问题是:我需要掷3个骰子。如果两个(或三个)骰子返回相同的数字,停止。如果3个骰子都是唯一的(例如2、4和6),则再次掷骰子。进行此操作,直到两倍/三倍滚动,或7次,以先到者为准。在

注意:我是一个python新手。在

到目前为止,我所得到的只是生成216种可能的组合:import itertools

all_possible = list(itertools.permutations([1,2,3,4,5,6],3))

input = raw_input()

print all_possible

生成这种类型的输出:

[(1, 2, 3), (1, 2, 4), (1, 2, 5), (1, 2, 6), (1, 3, 2), (1, 3, 4), (1, 3, 5), (1, 3, 6), (1, 4, 2), (1, 4, 3), (1, 4, 5), (1, 4, 6), (1, 5, 2), (1, 5, 3), (1, 5, 4), (1, 5, 6), (1, 6, 2), (1, 6, 3), (1, 6, 4), (1, 6, 5), (2, 1, 3), (2, 1, 4), (2, 1, 5), (2, 1, 6), (2, 3, 1), (2, 3, 4), (2, 3, 5), (2, 3, 6), (2, 4, 1), (2, 4, 3), (2, 4, 5), (2, 4, 6), (2, 5, 1), (2, 5, 3), (2, 5, 4), (2, 5, 6), (2, 6, 1), (2, 6, 3), (2, 6, 4), (2, 6, 5), (3, 1, 2), (3, 1, 4), (3, 1, 5), (3, 1, 6), (3, 2, 1), (3, 2, 4), (3, 2, 5), (3, 2, 6), (3, 4, 1), (3, 4, 2), (3, 4, 5), (3, 4, 6), (3, 5, 1), (3, 5, 2), (3, 5, 4), (3, 5, 6), (3, 6, 1), (3, 6, 2), (3, 6, 4), (3, 6, 5), (4, 1, 2), (4, 1, 3), (4, 1, 5), (4, 1, 6), (4, 2, 1), (4, 2, 3), (4, 2, 5), (4, 2, 6), (4, 3, 1), (4, 3, 2), (4, 3, 5), (4, 3, 6), (4, 5, 1), (4, 5, 2), (4, 5, 3), (4, 5, 6), (4, 6, 1), (4, 6, 2), (4, 6, 3), (4, 6, 5), (5, 1, 2), (5, 1, 3), (5, 1, 4), (5, 1, 6), (5, 2, 1), (5, 2, 3), (5, 2, 4), (5, 2, 6), (5, 3, 1), (5, 3, 2), (5, 3, 4), (5, 3, 6), (5, 4, 1), (5, 4, 2), (5, 4, 3), (5, 4, 6), (5, 6, 1), (5, 6, 2), (5, 6, 3), (5, 6, 4), (6, 1, 2), (6, 1, 3), (6, 1, 4), (6, 1, 5), (6, 2, 1), (6, 2, 3), (6, 2, 4), (6, 2, 5), (6, 3, 1), (6, 3, 2), (6, 3, 4), (6, 3, 5), (6, 4, 1), (6, 4, 2), (6, 4, 3), (6, 4, 5), (6, 5, 1), (6, 5, 2), (6, 5, 3), (6, 5, 4)]

这也不是很好,因为它只会产生双倍或三倍的结果,就我所知,一切都只是唯一的组合。在

------------更新-----------

好的——我取了这个,通过从数组中剥离每个值并求和(可能以最低效的方式)对其进行了扩展。它可以工作,如果在中断之前生成了多个集合,它们都会打印出来。我现在想做的是求和。所以:

^{pr2}$

下面是输出示例:How many tervigons? ::>3

Let's calculate some termagants based on 3 tervigons...

You'll get a minimum of 9 termagants per turn.

You'll get a maximum of 54 termagants per turn.

minimums: 5 turns [45] :: 6 turns [54] :: 7 turns [63]

averages: 5 turns [157] :: 6 turns [189] :: 7 turns [220]

maximums: 5 turns [270] :: 6 turns [324] :: 7 turns [378]

Total: 9

Total: 8

所以在这个例子中,我希望它返回17(即9+8)。在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值