Skip to content

Instantly share code, notes, and snippets.

@n0nick
Created January 20, 2015 09:40
Show Gist options
  • Save n0nick/37a2ea7fa44207fdef89 to your computer and use it in GitHub Desktop.
Save n0nick/37a2ea7fa44207fdef89 to your computer and use it in GitHub Desktop.
def score(dice)
dice.sort.each_slice(3).inject(0) do |score, slice|
score +
if slice.count(slice.first) == 3
slice[0] == 1 ? 1000 : slice[0] * 100
else
slice.inject(0) do |slice_score, num|
slice_score + (num == 1 ? 100 : num == 5 ? 50 : 0)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment