鱼C论坛

 找回密码
 立即注册
查看: 2023|回复: 3

[已解决]codewars Greed is good

[复制链接]
发表于 2019-12-23 15:33:26 | 显示全部楼层 |阅读模式

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

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

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


  1. def score(list1):
  2.     scoreset = {1, 2, 3, 4, 5, 6}
  3.     scoredict = {}
  4.     for each in scoreset:
  5.         scoredict[each] = list1.count(each)
  6.         
  7.     res = 0
  8.     if scoredict[1] <= 2:
  9.         res += 100 * scoredict[1]
  10.     else:
  11.         res += 700 + 100 * scoredict[1]

  12.     if scoredict[5] <= 2:
  13.         res += 50 * scoredict[5]
  14.     else:
  15.         res += 350 + 50 * scoredict[5]

  16.     if scoredict[6] == 3:
  17.         res += 600
  18.     else: pass

  19.     if scoredict[4] == 3:
  20.         res += 400
  21.     else: pass

  22.     if scoredict[3] == 3:
  23.         res += 300
  24.     else: pass

  25.     if scoredict[2] == 3:
  26.         res += 200
  27.     else: pass

  28.     return res
  29.    
  30. print(score( [3, 3, 3, 2, 2]))
  31. print(score( [2, 2, 2, 5, 5]))
  32. print(score( [1, 1, 5, 5, 4]))

  33. print(score( [2, 2, 1, 6, 2]))

复制代码
最佳答案
2019-12-23 15:53:40
经过验证你的程序没问题我带入列表和元组都符合题目要求,你的数值也正确。我只能猜可能list不对 他也没说如何将五个数传给你  有可能是收集参数 *list 你试试改成收集参数 主体程序不变。
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-12-23 15:53:40 | 显示全部楼层    本楼为最佳答案   
经过验证你的程序没问题我带入列表和元组都符合题目要求,你的数值也正确。我只能猜可能list不对 他也没说如何将五个数传给你  有可能是收集参数 *list 你试试改成收集参数 主体程序不变。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-12-23 16:11:25 | 显示全部楼层
贴个题目地址看看
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-12-23 16:19:04 | 显示全部楼层
https://www.codewars.com/kata/5270d0d18625160ada0000e4

网速有时候比较慢。
学了2个月,做了好多题目,才到6段。。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-7-17 17:11

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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