ruby/koans/about_scoring_project.rb
def score(dice)
  counts = dice.reduce(Hash.new(0)) do |h, i|
    h[i] += 1
    h
  end
  counts.reduce(0) do |sum, kv|
    number, count = kv
    case number
      when 1
        sum += (count / 3) * 1000 + (count % 3) * 100
      when 5
        sum += (count / 3) * 5 * 100 + (count % 3) * 50
      else
        sum += (count / 3) * 100 * number
    end
    sum
  end
end
# Greed is a dice game where you roll up to five dice to accumulate
# points.  The following "score" function will be used to calculate the
# score of a single roll of the dice.
#
# A greed roll is scored as follows:
#
# * A set of three ones is 1000 points
#
# * A set of three numbers (other than ones) is worth 100 times the
#   number. (e.g. three fives is 500 points).
#
# * A one (that is not part of a set of three) is worth 100 points.
#
# * A five (that is not part of a set of three) is worth 50 points.
#
# * Everything else is worth 0 points.
#
#
# Examples:
#
# score([1,1,1,5,1]) => 1150 points
# score([2,3,4,6,2]) => 0 points
# score([3,4,5,3,3]) => 350 points
# score([1,5,1,2,4]) => 250 points
#
# More scoring examples are given in the tests below:
#
# Your goal is to write the score method.
Greed is a dice game where you roll up to five dice to accumulate
points.  The following "score" function will be used to calculate the
score of a single roll of the dice.

A greed roll is scored as follows.

A set of three ones is 1000 points

A set of three numbers (other than ones) is worth 100 times the
number.

A one (that is not part of a set of three) is worth 100 points.

A five (that is not part of a set of three) is worth 50 points.

Everything else is worth 0 points.





More scoring examples are given in the tests below.

Your goal is to write the score method.
Greed is a dice game where you roll up to five dice to accumulate points . The following " score " function will be used to calculate the score of a single roll of the dice . A greed roll is scored as follows . A set of three ones is 1000 points A set of three numbers ( other than ones ) is worth 100 times the number . A one ( that is not part of a set of three ) is worth 100 points . A five ( that is not part of a set of three ) is worth 50 points . Everything else is worth 0 points . More scoring examples are given in the tests below . Your goal is to write the score method .
def score(dice)
  counts = dice.reduce(Hash.new(0)) do |h, i|
    h[i] += 1
    h
  end
  counts.reduce(0) do |sum, kv|
    number, count = kv
    case number
      when 1
        sum += (count / 3) * 1000 + (count % 3) * 100
      when 5
        sum += (count / 3) * 5 * 100 + (count % 3) * 50
      else
        sum += (count / 3) * 100 * number
    end
    sum
  end
end
def score ( dice ) counts = dice . reduce ( Hash . new ( 0 ) ) do | h , i | h [ i ] += 1 h end counts . reduce ( 0 ) do | sum , kv | number , count = kv case number when 1 sum += ( count / 3 ) * 1000 + ( count % 3 ) * 100 when 5 sum += ( count / 3 ) * 5 * 100 + ( count % 3 ) * 50 else sum += ( count / 3 ) * 100 * number end sum end end
Greed is a dice game where you roll up to five dice to accumulate
points.
Greed is a dice game where you roll up to five dice to accumulate points .
dice