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

I'm working on problem set 6, part 3. I already have a function that creates a words-to-points dictionary. I'm stuck on implementing a computer player. It would have to go through all the possible letter combinations and check if they're legitimate words and what their score is, but I can't think of how to plan a loop that will give all the possible combinations- especially since we don't know in advance how many letters there will be in each hand. Could someone please help me with this problem?

OpenStudy (e.mccormick):

What have you done with arrays so far? See, you can cycle through an array based on its length or via doing a single event for each item entered in it.

OpenStudy (anonymous):

create a loop that implements a random selection (of a letter) per iteration and check to see if it's in the words dict, then tally the score. find some ways to shorten overall run time like by abandoning low scoring word paths, i.e. a word of a higher point value has already been made, etc...

OpenStudy (anonymous):

Thanks a lot for your answers! I'm afraid I still don't understand how to do this problem. e.mccormick- I haven't worked with arrays so far, so I'm not exactly sure what they are or how to work with them (maybe this is something that will be covered later than I am in the course). mixalot- I'm stuck on how to implement a loop that will go through all the possible letter combinations in a given hand. I would appreciate some guidance on this point specifically.

OpenStudy (e.mccormick):

A dictionary is basically a form of array. Array, as a generic term, means something similar to the mathematical use of the word set or the generic use of the phrase organized group. So the dictionary you make is sort of an array. Also, a string in Python can be used as an array of characters. Each character is one letter in a word, a space, punctuation, etc.

OpenStudy (anonymous):

Thanks for your help! I ended up solving this question in a different way- instead of trying to create all the possible letter combinations, I went through the dictionary of possible words, checking each word to see if its letters exist in the current hand.

OpenStudy (e.mccormick):

Glad that worked for you.

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!