Working on PS6, problem 4. I think I've got the hand and word list ordering themselves alphabetically, but now that I'm trying to find the word with the maximum value, I just realized the problem with the whole approach "if word in hand".... This means "word" has to be a substring of "hand", correct? So if you're looking for the highest scoring word for the hand, you may have to get words that aren't consecutive substrings. For example, with the (sorted) hand "a c f i s t x", I'm returning the word "fisc" (all letters are consecutive), when I should be getting "fix" for the highest score.
I know part of the assignment was to change the psuedo-code provided from the initial any word-finding function to one that returns the maximum score, and I've done this in that I'm finding the maximum word value of all words with consecutive alphabetical letters in the hand, but my question is, are you really gaining any performance by sorting alphabetically if you then have to look through the whole hand anyway?
woah, just read through the assignment again and realized we're supposed to create an alphabetical list for every SUBSET of the hand. I just created one list for the whole hand. Working on that now...
I am also working on this one. I'm having trouble coming up with a good way to get all the subsets of the hand. Any insights you've found so far?
Vertigo, read through that power set wiki you posted in the other thread http://en.wikipedia.org/wiki/Power_set ...so there are 2^n subsets for a single set of size n. Not easy to organize the code to enumerate them..
yikes! An entire 54-minute lecture!!? http://academicearth.org/lectures/writing-recursive-power-set-function-in-scheme
http://dpaste.com/hold/576115/ i have written this piece of code just to get all the subsets ... now i think we just need to check for valid words and then pick the highest scoring one.. i havent seen the problems yet...just did this part -_-
ah you found some built-in permutations thing, nice! This is the recursive solution, found it online: def powerset(seq): if len(seq): head = powerset(seq[:-1]) return head + [item + [seq[-1]] for item in head] else: return [[]]
For everything using the itertools solution as well. http://dpaste.com/577506/
@baronvonholback: You should be getting "fixt" instead of "fix"
i believe there is a combination function in itertools as well which may help
Join our real-time social learning platform and learn together with your friends!