Skip to content

Instantly share code, notes, and snippets.

@ehutzelman
Created July 19, 2011 05:58
Show Gist options
  • Select an option

  • Save ehutzelman/1091431 to your computer and use it in GitHub Desktop.

Select an option

Save ehutzelman/1091431 to your computer and use it in GitHub Desktop.
GreedRoll implementation: Ruby Koans
class GreedScore
def initialize(dice)
@values = dice.sort
end
def calculate
@score = 0
score_triples
score_singles
@score
end
private
def score_triples
(1..6).each do |match|
if @values.count(match) >= 3
@score += match * (match == 1 ? 1000 : 100)
@values = @values.drop(3)
end
end
end
def score_singles
@values.each do |value|
@score += 100 if value == 1
@score += 50 if value == 5
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment