Skip to content

Instantly share code, notes, and snippets.

@flarnie
Created June 15, 2013 23:47
Show Gist options
  • Save flarnie/5790071 to your computer and use it in GitHub Desktop.
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.
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