Created
November 10, 2016 13:59
-
-
Save m3talstorm/b0d31d07877224e41b18ba73e348c829 to your computer and use it in GitHub Desktop.
Scrabble word score
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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
python scrabble.py hello