Created
September 13, 2013 16:44
-
-
Save eriknomitch/6553106 to your computer and use it in GitHub Desktop.
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
def score(dice, total=0) | |
# * A set of three ones is 1000 points | |
if dice.select {|d| d == 1}.length >= 3 | |
3.times {|i| dice.delete_at(dice.index(1)) } | |
return score dice, 1000 | |
end | |
# * A set of three numbers (other than ones) is worth 100 times the | |
# number. (e.g. three fives is 500 points). | |
(1..6).each do |i| | |
if dice.select {|d| d == i}.length >= 3 | |
total += i * 100 | |
end | |
end | |
# * A five (that is not part of a set of three) is worth 50 points. | |
total += 50 * dice.select{|d| d == 5}.length | |
# * A one (that is not part of a set of three) is worth 100 points. | |
total += 100 * dice.select{|d| d == 1}.length | |
total | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment