Skip to content

Instantly share code, notes, and snippets.

@caseyhoward
Created July 14, 2011 16:43
Show Gist options
  • Save caseyhoward/1082829 to your computer and use it in GitHub Desktop.
Save caseyhoward/1082829 to your computer and use it in GitHub Desktop.
def score(dice)
counts = (1..6).inject({}) do |counts, number|
counts[number] = dice.count(number)
counts
end
total = counts.inject(0) do |total, (number, count)|
if count >= 3
counts[number] -= 3
total += (number == 1 ? 1000 : 100) * number
end
total
end
total += counts[1] * 100
total += counts[5] * 50
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment