Computer Science Canada help with anagram finder |
Author: | JakeTakeLake [ Fri Oct 18, 2013 9:22 pm ] | ||
Post subject: | help with anagram finder | ||
What is it you are trying to achieve? I'm trying to make an anagram finder. i put in a word, then the program finds all the anagrams of that word from a text file with all the words from a dictionary. What is the problem you are having? the program finds all the anagrams, but some are wrong. the main problem is the words normally have double letters. i understand the concept, but there must be a small problem that i've overlooked. Describe what you have tried to solve this problem i've tried subtracting the letter each time there is a match to the word and at the end testing whether all the letters are removed. i've also tried using an array to "cancel" a letter when it makes a match to a letter in the other word, so that there are no repeated letters. Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) ask if u want the webster.txt
Please specify what version of Turing you are using 4.1.1 |
Author: | Dreadnought [ Fri Oct 18, 2013 10:45 pm ] | ||||||
Post subject: | Re: help with anagram finder | ||||||
So basically it looks like the following scenario would cause a problem.
but this one wont
Let's examine some of the logic in your code. So you go through each letter of word and check if it appears in s. What exactly do you want to do when you find the letter in s? What crucial little step are you missing? Hint:
|
Author: | JakeTakeLake [ Sat Oct 19, 2013 9:25 am ] | ||||
Post subject: | Re: help with anagram finder | ||||
[quote="Dreadnought @ Fri Oct 18, 2013"]So basically it looks like the following scenario would cause a problem.
but this one wont
ok i got it working. this is what helped me. i just made another spot variable. so when it matches a letter it takes up the spots of j AND i. thanks |
Author: | Dreadnought [ Sat Oct 19, 2013 10:24 am ] |
Post subject: | Re: help with anagram finder |
JakeTakeLake wrote: ok i got it working. this is what helped me. i just made another spot variable. so when it matches a letter it takes up the spots of j AND i. thanks That works, another (perhaps more natural) way of doing it would be to exit the innermost for loop when you find a letter (right after spostaken := spotstaken + 1). This would stop the program from matching a letter of word[/d] multiple times. It's really a matter of preference, but I thought you might be interested in another way of approaching things. |
Author: | Raknarg [ Sat Oct 19, 2013 11:54 am ] |
Post subject: | RE:help with anagram finder |
A nice simple method too would be to sort both strings and see if they're the same |