anonymous
  • anonymous
PS#6, problem 4: I am having a hard time understanding what it is asking me to do. Is it asking me to find all possible permutations in a hand and call it rearrange_dict, then passing each key through is_valid_word? I was able to do problem 3 fine code is below just in case I approached it wrong (which may be the reason I don't understand what is asked in problem 4). Please help! http://codepad.org/1RSxtXDm
MIT 6.00 Intro Computer Science (OCW)
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
jamiebookeater
  • jamiebookeater
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
alwahsh posted some code below. So did I.
anonymous
  • anonymous
rearrange dictionary keys are the sorted words and the values are the words {sorted(word) : word} 'alpha' --> {'aahlp' : 'alpha'} then you can say something like find the highest scoring key in the rearranged dictionary that is a sorted(subset) of hand or for every sorted(subset) of hand which corresponding rearranged dictionary key has the highest value
anonymous
  • anonymous
not entirely sure what is going on or why sorting each word first makes it faster.... Will go struggle a little longer and read through the older posts. Thanks!

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

anonymous
  • anonymous
it's faster because the dictionary is accessed in constant time (I believe). so here are the steps (and example with 'hunt'): -sort the word: e.g. hntu -create all the subsets of the sorted word: e.g. h, n, hn, t, th, tn, thn, u, uh, un, uhn,ut,uth,utn,uthn -now you have a list with 15 elements (2**4 -1) -iterate over the 15 elements to find the highest score. since you already have the rearranged_dict, you're just plugging in the subsets as the keys. iterating through 15 elements is faster than iterating through the whole dictionary every time.
anonymous
  • anonymous
in the previous problem you should have had to test all the (subset) permutations of hand to find the best word. you have to look for 'aac' and 'aca' and 'caa' with the rearranged dictionary the keys are sorted so a word that contains the letters a, a, and you only have to use (sorted) combinations of hand ('aac' only) and there are a lot less combinations than permutations. hope that made sense
anonymous
  • anonymous
I didn't use permutations on the previous problem which is probably why I was having difficulty grasping how sorting it like the pset suggested was going to make it faster as I didn't see how I was going to avoid looping through the whole wordfile at least once. But between the both of you, I think it is crystal clear what is being asked. Thanks!
anonymous
  • anonymous
you shouldn't have to loop. you can use the in or not in operators http://docs.python.org/reference/expressions.html#in
anonymous
  • anonymous
nope didn't need to loop after all the help I got from you guys - so thanks for that!. Only looped once through the list of combinations rather than the whole dictionary

Looking for something else?

Not the answer you are looking for? Search for more explanations.