Ruby on Rails
- 1 ответ
- 0 вопросов
0
Вклад в тег
def score(dice)
# You need to write this method
digits = Hash.new(0)
dice.each { |n| digits[n] += 1 }
result = 0
result += 1000 if digits[1] >= 3 # 1
(digits.keys - [1]).each do |n| # 2
result += n * 100 if digits[n] >= 3
end
result += 100 * (digits[1] % 3) # 3
result += 50 * (digits[5] % 3) # 4
result
end