forked from jesstess/Wordplay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscrabble_cheater.py
32 lines (26 loc) · 925 Bytes
/
scrabble_cheater.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import sys
from scrabble import wordlist, scores
if __name__ == "__main__":
if len(sys.argv) < 2:
print >>sys.stderr, "Usage: scrabble.py [RACK]"
sys.exit(1)
rack = list(sys.argv[1].lower())
valid_words = []
for word in wordlist:
# Make a copy of the rack for every new word, so we can manipulate it
# without compromising the original rack.
available_letters = rack[:]
valid = True
for letter in word.lower():
if letter not in available_letters:
valid = False
break
available_letters.remove(letter)
if valid:
# Calculate the Scrabble score.
score = 0
for letter in word:
score = score + scores[letter]
valid_words.append((score, word))
for play in sorted(valid_words, reverse=True):
print play[0], play[1]