Skip to content

Instantly share code, notes, and snippets.

@Dispader
Last active August 29, 2015 14:00
Show Gist options
  • Select an option

  • Save Dispader/11231685 to your computer and use it in GitHub Desktop.

Select an option

Save Dispader/11231685 to your computer and use it in GitHub Desktop.
def score(dice)
score = 0
roll_count = dice.inject(Hash.new(0)) { |roll, count|
roll[count] += 1; roll
}
roll_count.each { |roll, count|
if count >= 3
if roll == 1
score += 1000
else
score += roll * 100
end
count -= 3
end
if roll == 1
score += count * 100
elsif roll == 5
score += count * 50
end
}
return score
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment