|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
又是一题codewars 题目。
看上去很简单的题目,提交代码后总是通不过,在110个例子中总是错了一个例子。很头疼。
有没有大师帮忙解读一下
Greed is a dice game played with five six-sided dice. Your mission, should you choose to accept it, is to score a throw according to these rules. You will always be given an array with five six-sided dice values.
Three 1's => 1000 points
Three 6's => 600 points
Three 5's => 500 points
Three 4's => 400 points
Three 3's => 300 points
Three 2's => 200 points
One 1 => 100 points
One 5 => 50 point
A single die can only be counted once in each roll. For example, a "5" can only count as part of a triplet (contributing to the 500 points) or as a single 50 points, but not both in the same roll.
Example scoring
Throw Score
--------- ------------------
5 1 3 4 1 50 + 2 * 100 = 250
1 1 1 3 1 1000 + 100 = 1100
2 4 4 5 4 400 + 50 = 450
- def score(list1):
- scoreset = {1, 2, 3, 4, 5, 6}
- scoredict = {}
- for each in scoreset:
- scoredict[each] = list1.count(each)
-
- res = 0
- if scoredict[1] <= 2:
- res += 100 * scoredict[1]
- else:
- res += 700 + 100 * scoredict[1]
- if scoredict[5] <= 2:
- res += 50 * scoredict[5]
- else:
- res += 350 + 50 * scoredict[5]
- if scoredict[6] == 3:
- res += 600
- else: pass
- if scoredict[4] == 3:
- res += 400
- else: pass
- if scoredict[3] == 3:
- res += 300
- else: pass
- if scoredict[2] == 3:
- res += 200
- else: pass
- return res
-
- print(score( [3, 3, 3, 2, 2]))
- print(score( [2, 2, 2, 5, 5]))
- print(score( [1, 1, 5, 5, 4]))
- print(score( [2, 2, 1, 6, 2]))
复制代码
经过验证你的程序没问题我带入列表和元组都符合题目要求,你的数值也正确。我只能猜可能list不对 他也没说如何将五个数传给你 有可能是收集参数 *list 你试试改成收集参数 主体程序不变。
|
|