Created
July 19, 2011 05:58
-
-
Save ehutzelman/1091431 to your computer and use it in GitHub Desktop.
GreedRoll implementation: Ruby Koans
This file contains hidden or 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
| 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