Created
June 15, 2013 23:47
-
-
Save flarnie/5790071 to your computer and use it in GitHub Desktop.
My initial solution to 'about_scoring_project' from Neo Ruby Koans ( http://rubykoans.com/ ), koans 183-190.
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
def score(dice) | |
# You need to write this method | |
total_score = 0 | |
def miniscore(n, c) | |
triple = n * 100 | |
single = 0 | |
if n == 1 | |
triple = 1000 | |
single = c >= 3 ? (c-3) * 100 : c * 100 | |
elsif n == 5 | |
triple = n * 100 | |
single = c >= 3 ? (c-3) * 50 : c * 50 | |
end | |
if c >= 3 | |
return triple + single | |
else | |
return single | |
end | |
end #end miniscore(n, c) | |
for n in dice.uniq | |
c = dice.count(n) | |
total_score += miniscore(n, c) | |
end | |
total_score | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment