一个投骰子的游戏,投五次,对应得分如下
1,1,1 => 1000 points
6,6,6 => 600 points
5,5,5 => 500 points
4,4,4 => 400 points
3,3,3 => 300 points
2,2,2 => 200 points
1 => 100 points
5 => 50 point
Throw Score
--------- ------------------------------------------------
5 1 3 4 1 250: 50 (for the 5) + 2 * 100 (for the 1s)
1 1 1 3 1 1100: 1000 (for three 1s) + 100 (for the other 1)
2 4 4 5 4 450: 400 (for three 4s) + 50 (for the 5)
第二个for循环不理解
def score(dice):
sum = 0
counter = [0, 0, 0, 0, 0, 0]
points = [1000, 200, 300, 400, 500, 600]
extra = [100, 0, 0, 0, 50, 0]
for die in dice:
counter[die - 1] += 1
for (i, count) in enumerate(counter):
sum += (points[i] if count >= 3 else 0) + extra[i] * (count % 3)
return sum
print(score([5, 1, 3, 4, 1]))