Skip to content

Instantly share code, notes, and snippets.

@mooreniemi
Created October 31, 2012 01:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mooreniemi/3984241 to your computer and use it in GitHub Desktop.
Save mooreniemi/3984241 to your computer and use it in GitHub Desktop.
600x PS4
def compChooseWord(hand, wordList):
"""
Given a hand and a wordList, find the word that gives
the maximum value score, and return it.
This word should be calculated by considering all the words
in the wordList.
If no words in the wordList can be made from the hand, return None.
hand: dictionary (string -> int)
wordList: list (string)
returns: string or None
"""
# Create a new variable to store the maximum score seen so far (initially 0)
maxScore = 0
# Create a new variable to store the best word seen so far (initially None)
bestWord = None
value = 0
# For each word in the wordList
for word in wordList:
# If you can construct the word from your hand
# (hint: you can use isValidWord, or - since you don't really need to test if the word is in the wordList - you can make a similar function that omits that test)
if isValidWord(word, hand, wordList) == True:
# Find out how much making that word is worth
value = getWordScore(word, HAND_SIZE)
#print value
# If the score for that word is higher than your best score
if value > maxScore:
# Update your best score, and best word accordingly
maxScore = value
bestWord = word
#print maxScore
#print bestWord
return bestWord
# return the best word you found.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment