Skip to content

Instantly share code, notes, and snippets.

@m3talstorm
Created November 10, 2016 13:59
Show Gist options
  • Save m3talstorm/b0d31d07877224e41b18ba73e348c829 to your computer and use it in GitHub Desktop.
Save m3talstorm/b0d31d07877224e41b18ba73e348c829 to your computer and use it in GitHub Desktop.
Scrabble word score
import sys
# https://en.wikipedia.org/wiki/Scrabble_letter_distributions
SCORES = {
'E' : 1,
'A' : 1,
'I' : 1,
'O' : 1,
'N' : 1,
'R' : 1,
'T' : 1,
'L' : 1,
'S' : 1,
'U' : 1,
'D' : 2,
'G' : 2,
'B' : 3,
'C' : 3,
'M' : 3,
'P' : 3,
'F' : 4,
'H' : 4,
'V' : 4,
'W' : 4,
'Y' : 4,
'K' : 5,
'J' : 8,
'X' : 8,
'Q' : 10,
'Z' : 10,
}
if len(sys.argv) < 2:
raise Exception("No word provided")
word = sys.argv[1]
total = 0
for letter in word.upper():
score = SCORES.get(letter)
if not score:
raise Exception("Unknown letter %s" % (letter))
total += score
print total
@m3talstorm
Copy link
Author

python scrabble.py hello

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment