Coding Academy - WordScramble Homework Help

Code junkies hangout here

Moderators: ChrisThornett, LXF moderators

Coding Academy - WordScramble Homework Help

Postby rikoshay2020 » Fri Feb 05, 2010 3:59 pm


I've got all of the homework for WordScramble done apart from part 4 which is driving me somewhat nuts! Mostly because I thought it should be really easy and whatever I try just seems to end up compiling fine but then not functioning quite as I want it.

I've tried several different approaches and the one I think was in the right direction was adding an extra bit to the WordIsPossible method whereby if the int value of letters = 0 (i.e. all letters have been used) it returns false and the word is not possible. I realise that this would not exclude anagrams. This felt right as I wasn't simply comparing input against PromptLetters (which I tried and still couldn't get to work).

Any pointers greatly appreciated as I really want to try and get it sorted before moving on to Project 3.

Posts: 6
Joined: Sun Jan 24, 2010 6:17 pm

Postby Hudzilla » Fri Feb 05, 2010 6:43 pm


You're right to want to complete the homework before continuing - it sounds crazy, but banging your head against a wall before solving the problem will really help you in the long run :)

I don't know why your code isn't compiling; you'd have to give me some source code and the error messages to help with that. The homework you're referring to asks you to stop the player from entering the same word used to generate their prompt letters. So, if the letters are "w o m b a t" don't let them enter the word "wombat".

The text tells you that the smart solution isn't to compare against the prompt letters. The reason for this is that the prompt letters have spaces between every letter, which is painful to compare against.

So, you have two options here:

1) Creating a new set of prompt letters involves pulling a word from our dictionary. How about adding that word straight to the Used List?

2) What about storing the chosen word in a new variable, then comparing the player's against that?

User avatar
Site admin
Posts: 265
Joined: Mon Apr 04, 2005 11:52 am
Location: LXF Towers

Postby rikoshay2020 » Sat Feb 06, 2010 1:34 am

Thanks Paul. I sorted it with option 2 - creating a new variable. Copying word (not PromptLetters which was where I was going wrong) into it and adding a new else condition. On to project three! Thanks. Rik
Posts: 6
Joined: Sun Jan 24, 2010 6:17 pm

WordScramble Homework Part 4

Postby bargem » Sat Feb 06, 2010 8:34 pm

Hi there!

Thanks Rikoshay2020 for asking the question and to Paul for providing a couple of ways into the problem.

Like Rikoshay2020, I'd spent ages trying to figure out how to get this to work and didn't want to progress to Project Three until I'd cracked it.

First I tried to compare user input with PromptLetters (despite Paul's advice not to in the homework), but then realized PromptLetters had spaces between each letter. So I then tried to create a method to put spaces into the input word before comparing to PromptLetters - couldn't get that to work :( . So then tried to create a method to remove the spaces from PromptLetters before checking against input - couldn't get that to work either :x .

So have now also tried Paul's second option and created a new variable to hold the word taken from the wordlist file - which is set before the spaces are added to PromptLetters. This is then compared with the user's input in my new method. It works! :D

Cheers! On to Project Three!!
Posts: 1
Joined: Sat Feb 06, 2010 6:42 pm

Postby branmask » Thu Mar 04, 2010 7:45 am

Yes, thanks Paul for the suggestions. I figured out a very simple way to use your first suggestion. It has something to do with UsedList.Add and GetLetters. Amazing how something can seem so complicated, yet be so simple... :-) Thanks again.

Warning! spoiler ahead. code to follow. if you want to figure it out for yourself, don't read the rest of my comment...

Posts: 14
Joined: Thu Feb 18, 2010 1:19 am

Return to Programming

Who is online

Users browsing this forum: No registered users and 1 guest