Created
October 23, 2021 21:34
-
-
Save Niall47/41595c1330aa08f0f19c76fac59cc3c1 to your computer and use it in GitHub Desktop.
scrabble scoring
This file contains 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
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