id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

peter@norvig.com scrabble > scrabble_best_play_fast
prev  |  next  |  chance

The problem with scrabble_best_play, from the previous exercise, is that it has to test every word in the dictionary for every position on the board. That's no problem when the dictionary has only 17 words and the board 9 squares, but a real Scrabble dictionary is 10,000 times bigger, and the board is 25 times bigger. In this sixth Scrabble exercise, you will define scrabble_best_play_fast(row, rack), which, unsurprisingly, is just like scrabble_best_play, but faster. Instead of trying every word at every position, start only at ANCHOR positions, which are next to existing letters, and then only grow out from the anchors, one square at a time, stopping when there is no letter that forms a part of a word, and yielding a word when we row one. As before, the result you return should be a list [score, k, word], where k is the position in row where word can be placed to yield 'score' points. Use a slightly larger dictionary: dictionary = "ONE TWO THREE FOUR FIVE SIX HELL HELLO WORLD ROLLED ROLL WELL OXYGEN OXYGENATED OXYGENIZE LOW OTHER MOTHER HER THE THERE WELL ELL TEE TOE OXEN ZOO ZOOM LOX MOXIE TOXIC TOXICOLOGY ZOOLOGY AA AB AD AE AG AH AI AL AM AN AR AS AT AW AX AY BA BE BI BO BY DE DO ED EF EH EL EM EN ER ES ET EX FA GO HA HE HI HM HO ID IF IN IS IT JO KA LA LI LO MA ME MI MM MO MU MY NA NE NO NU OD OE OF OH OM ON OP OR OS OW OX OY PA PE PI RE SH SI SO TA TI TO UH UM UN UP US UT WE WO XI XU YA YE YO ".split()


scrabble_best_play_fast([-3, 1, 2, 1, 0, 1, 2, 1, -3], 'GLYZOOO') → [227, 2, 'ZOOLOGY']
scrabble_best_play_fast([-3, 1, 2, 1, 0, 1, 2, 1, -3], 'EMTHRNO') → [60, 4, 'OTHER']
scrabble_best_play_fast([-3, 1, 2, 1, 1, 'O', 2, 1, -3], 'ELTXRNO') → [60, 5, 'OXEN']

...Save, Compile, Run (ctrl-enter)

def scrabble_best_play_fast(row, rack):

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Python Help

Difficulty: 475 Post-solution available

Copyright Nick Parlante 2017 - privacy