Skip to content

Instantly share code, notes, and snippets.

@irmiller22
Created December 6, 2013 19:16
Show Gist options
  • Save irmiller22/7830542 to your computer and use it in GitHub Desktop.
Save irmiller22/7830542 to your computer and use it in GitHub Desktop.
Greed Score Logic
# 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