Skip to content

Instantly share code, notes, and snippets.

@vosechu
Created June 13, 2013 18:13
Show Gist options
  • Save vosechu/5775993 to your computer and use it in GitHub Desktop.
Save vosechu/5775993 to your computer and use it in GitHub Desktop.
Scrabble scorer via regex
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