Skip to content

Instantly share code, notes, and snippets.

@Niall47
Created October 23, 2021 21:34
Show Gist options
  • Save Niall47/41595c1330aa08f0f19c76fac59cc3c1 to your computer and use it in GitHub Desktop.
Save Niall47/41595c1330aa08f0f19c76fac59cc3c1 to your computer and use it in GitHub Desktop.
scrabble scoring
scores = {
/[AEIOULNRST]/ => 1,
/[DG]/ => 2,
/[BCMP]/ => 3,
/[FHVWY]/ => 4,
/[K]/ => 5,
/[JX]/ => 8,
/[QZ]/ => 10
}
word = gets.chomp.upcase
points = 0
scores.each do |character, score|
hits = word.scan(character).count
points += (hits * score) if hits.positive?
end
puts points.to_s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment