Posts: 33
Threads: 8
Joined: Jan 2006
Hey Guys.
Im having problems making a word unscrambler program.
Ill give you an example..
atc = scrambled
cat = unscrambled.
I want it to get the unscrambled words from a worldlist file I have got. Its just that I want to input a valid scrambled up word and the program searches through the wordlist to find the correct one. I hope you can Help me.
Thanx Hybr!d
img]http://img213.imageshack.us/img213/6104/sig1jb.gif[/img]
Posts: 843
Threads: 60
Joined: Mar 2003
If you prove to me that you've at least tried doing this, I will assist in any way possible.
Posts: 33
Threads: 8
Joined: Jan 2006
I have just gathered Ideas firstly. I want to go around it like this.
1) Get the Length of the scrambled word.
2) Compare Length of scrambled word to unscrambled words in wordlist.
3) Then see if there are similar characters between the unscrambled and scarmbled word.
4) Print out the closest word to it.
img]http://img213.imageshack.us/img213/6104/sig1jb.gif[/img]
Posts: 2,771
Threads: 96
Joined: Oct 2003
Youve got the concept.
however there may be some complexities. If there was:
scrambled word: CCT
unscrambled list:
TCT
CTC
If you are comparing each letter in CCT in turn to see if it is in the unscrambled list word, It may detect TCT as the unscrambled word because it has similar letters (although they arent in the same number)
like this:
comparing:
is C in TCT? Yes!
is C in TCT yes!
is T in TCT yes!
even though CCT could not make TCT.
You could try making a temporary string in which each character is removed after it is found.
so it would do:
is C in TCT? yes!
is C in TT? No! (and then we can move to the next possible word, because a false was encountered)
is C in CTC? Yes!
is C in TC? yes!
is T in T? Yes! (and thus the word is correct)
If you dont know how to program this, come back and we will help.
To get you started, try using the INSTR() command. It will check if a specified character exists in a string. Look it up in the QB help for more details.
Posts: 29
Threads: 0
Joined: Dec 2005
This should do it...
Code:
FUNCTION CompareWord(ScambledWord AS STRING, Word AS STRING) AS STRING
DIM DummyX AS INTEGER
DIM fakeword AS STRING
IF LEN(word) <> LEN(ScambledWord) THEN return "Bad Length"
fakeword = ScambledWord
FOR DummyX = 1 TO LEN(ScambledWord)
'Check letter by letter and see if that letter is in the comparison string
IF INSTR(fakeword, mid(Word,DummyX,1)) THEN
'if it is remove that letter from our copy of the original string
MID(fakeword,INSTR(fakeword, mid(Word,DummyX,1)),1) = " "
END IF
NEXT DummyX
IF LEN(trim$(fakeword)) = 0 THEN
RETURN trim$(FakeWord)'we return an empty string if we succede
ELSE
RETURN trim$(fakeword)'if we fail we give back what we couldn't remove
END IF
END FUNCTION
Posts: 33
Threads: 8
Joined: Jan 2006
Andrew Collins Could you care to explain that code and how could I edit it so it could be able to get the unscrambled words from a wordlist?
img]http://img213.imageshack.us/img213/6104/sig1jb.gif[/img]
Posts: 29
Threads: 0
Joined: Dec 2005
a
Code:
OPTION EXPLICIT
DECLARE FUNCTION CompareWord(ScambledWord AS STRING, Word AS STRING) AS STRING
DIM text AS STRING
DIM DictWord AS STRING
DIM ScramWord AS STRING
SCREEN 0
text=""
DictWord = ""
ScramWord = ""
DO
IF DictWord = "auto mobile" THEN DictWord = "supercalifragilisticexpyallidousoues"
IF DictWord = "horse" THEN DictWord = "auto mobile"
IF DictWord = "cat" THEN DictWord = "horse"
IF DictWord = "" THEN DictWord = "cat"
IF DictWord = "supercalifragilisticexpyallidousoues" THEN ScramWord = "supercXlifragilisticexpyallidousoues"
IF DictWord = "auto mobile" THEN ScramWord = "elibo mtoua"
IF DictWord = "horse" THEN ScramWord = "rsoeh"
IF DictWord = "cat" THEN ScramWord = "tac"
'if the return length of our text is 0 then we have a match
'if the return length of our text is other than 0 then we have no match
'This code is also Case sensitive, I'll leave it up to you if you wish to make it case insensitive...
'ScramWord is the scrambled word...
'Dictword is the word from your dictionary...
text = CompareWord(ScramWord,dictword)
IF LEN (text) > 0 THEN
? "No Match ",DictWord, text
ELSE
? "Match", DictWord
END IF
LOOP UNTIL DictWord = "supercalifragilisticexpyallidousoues"
? "Press any key to exit"
SLEEP
FUNCTION CompareWord(ScambledWord AS STRING, Word AS STRING) AS STRING
DIM DummyX AS INTEGER
DIM fakeword AS STRING
IF LEN(word) <> LEN(ScambledWord) THEN return "Bad Length"
fakeword = ScambledWord
FOR DummyX = 1 TO LEN(ScambledWord)
'Check letter by letter and see if that letter is in the comparison string
IF INSTR(fakeword, mid(Word,DummyX,1)) THEN
'if it is remove that letter from our copy of the original string
MID(fakeword,INSTR(fakeword, mid(Word,DummyX,1)),1) = " "
END IF
NEXT DummyX
'this code here is seperated this way so you can modify it...
IF LEN(trim$(fakeword)) = 0 THEN
RETURN trim$(FakeWord)'this is success
ELSE
RETURN trim$(fakeword)'this is failure
END IF
END FUNCTION
Posts: 33
Threads: 8
Joined: Jan 2006
Hey thanks man. Im going to look over it. BTW do you have an email?? I wish to talk to you!!
img]http://img213.imageshack.us/img213/6104/sig1jb.gif[/img]
Posts: 2,771
Threads: 96
Joined: Oct 2003
Andrew, we usually like to help people solve problems here, instead of just giving them the answer. It promotes learning. Especially when the person is doing homework.
Posts: 1,774
Threads: 62
Joined: Aug 2003