Created
December 6, 2013 19:16
-
-
Save irmiller22/7830542 to your computer and use it in GitHub Desktop.
Greed Score Logic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# GREED GAME | |
def score(dice) | |
return 0 if dice == nil | |
score = 0 | |
counts = [0,0,0,0,0,0] | |
dice.each { |roll| counts[roll-1] += 1 if (1..6) === roll } | |
(1..6).each { |i| score += (i == 1) ? 1000 : i * 100 if counts[i-1] >= 3 } | |
score += counts[0] % 3 * 100 | |
score += counts[4] % 3 * 50 | |
return score | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment