Created
June 13, 2013 18:13
-
-
Save vosechu/5775993 to your computer and use it in GitHub Desktop.
Scrabble scorer via regex
This file contains hidden or 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
module ScrabbleScorer | |
POINTS = { | |
/[aeiou]/ => 1, | |
/[j]/ => 8, | |
/[qx]/ => 10 | |
} | |
def self.score(word) | |
sum = 0 | |
POINTS.each do |key, value| | |
sum += word.scan(key).length * value | |
end | |
return sum | |
end | |
end | |
p ScrabbleScorer.score('jcabbagex') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment