Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 21 Online
OpenStudy (anonymous):

I'm on ps6. I can code the computer pick best word method statically for all combinations of words up to 7 letters long, but does anyone know a way to do it dynamically. For instance based on the variable MAX_HAND_SIZE? thanks in advance, Alan

OpenStudy (anonymous):

Hi, i'm on this now, the simplest method seems to be to iterate though the points_dict word list, checking if it's a valid word and if it is the highest scoring so far. How are you doing it? I tried to write a recursive function to generate all possible combinations of the given letters but I couldn't figure it out. There is a function in the itertools module that does this: http://docs.python.org/library/itertools.html#itertools.permutations however I don't fully understand the code that it says it is equivalent to. This wiki page also seems relevent: https://secure.wikimedia.org/wikipedia/en/wiki/Permutations

OpenStudy (anonymous):

Well i wrote one method so far that took a given list of X number of characters and iterated through it X factorial with all the different possible permutations for that list. On a side note, how fast are you going through these assignments? It would be cool to have someone going at the same pace to compare things with.

OpenStudy (anonymous):

Stated about a week or two ago. here is what I have so far just moving onto problem 4 now, seems to work fine, but suggestions for improvement would be appreciated: http://codepad.org/13eJ44FG

OpenStudy (anonymous):

The set of all combinations you can make from a set of objects (called the "powerset" of the set) can be defined recursively: Base case: The powerset of the empty set is the set containing the empty set. Recursion: The powerset of a set with n elements (x1 through xn) is: the powerset of elements x1 through x(n-1), union the powerset of elements x1 through x(n-1) each with element xn added to it To put it into practice: The set of combinations for a hand with 0 letters is a set containing a single empty string. Given the powerset of the string 'ab' = { '', 'a', 'b', 'ab' } the powerset of 'abc' will be: { '', 'a', 'b', 'ab' }, union { 'c', 'ac', 'bc', 'abc' } (I just added c to each of the elements.) Given this, you should be able to write a recursive function that will generate a powerset for a sequence. Write and debug it in a separate file before putting into your ps6.py file. As a check, if a set has n elements, its powerset will have 2^n elements (each element will itself be a set, with between 0 and n elements). Normally you would use itertools to do this, but I think it's good practice for writing recursive functions, and just for learning programming in general.

OpenStudy (anonymous):

@mutley, I actually like your solution better than mine. Since the assignment isn't looking for efficiency, your seems like an easy implementation. @dmancine Thanks for the advice. I'll try getting that to work tomorrow and I'll let you know.

OpenStudy (anonymous):

http://codepad.org/7U6ECaA8

OpenStudy (anonymous):

Mutley - take a look at this line from your get_words_to_points method. points_dict[word] = get_word_score(word, len(word)) It 'thinks' every word deserves the 50 point bonus for using all the letters. I suggest little test methods for all your functions to check you get expected values. You have a nice, clear coding style. Good luck.

OpenStudy (anonymous):

@ ALearner: Thank you, fixed using HAND_SIZE instead.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!