| View previous topic :: View next topic |
| Author |
Message |
rikoshay2020
Joined: Sun Jan 24, 2010 6:17 pm Posts: 6
|
Posted: Fri Feb 05, 2010 3:59 pm Post subject: Coding Academy - WordScramble Homework Help |
|
|
Hi,
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.
Cheers. |
|
| Back to top |
|
 |
Hudzilla Site admin

Joined: Mon Apr 04, 2005 12:52 pm Posts: 265 Location: LXF Towers
|
Posted: Fri Feb 05, 2010 6:43 pm Post subject: |
|
|
Hey!
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?
Paul |
|
| Back to top |
|
 |
rikoshay2020
Joined: Sun Jan 24, 2010 6:17 pm Posts: 6
|
Posted: Sat Feb 06, 2010 1:34 am Post subject: |
|
|
| 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 |
|
| Back to top |
|
 |
bargem
Joined: Sat Feb 06, 2010 6:42 pm Posts: 1
|
Posted: Sat Feb 06, 2010 8:34 pm Post subject: WordScramble Homework Part 4 |
|
|
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 .
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!
Cheers! On to Project Three!! |
|
| Back to top |
|
 |
branmask
Joined: Thu Feb 18, 2010 1:19 am Posts: 14
|
Posted: Thu Mar 04, 2010 7:45 am Post subject: |
|
|
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...
GetLetters();
Console.WriteLine(PromptLetters);
UsedList.Add(PromptLetters); |
|
| Back to top |
|
 |
| View previous topic :: View next topic |
|