Page 1 of 1

anagram solver

Posted: Tue Aug 15, 2006 12:47 am
by Seb McClouth
Just for a try-out, I want to make a anagram solver, which is capable to solve up to 10 letters in a word.

Currently I can only use up to 3 letters, anyone to step in and help me out?

Code: Select all

DIM SHARED letters(9) AS STRING

LINE INPUT "Give in word: ", word$
PRINT "Wordlenght is "; LEN(word$)

FOR a = 1 to LEN(word$)
     letters(a) = MID$(word$, a, 1)
NEXT

Then I'm stuck. I do know that I have the following table:
[1-2-3]
[1-3-2]
[2-1-3]
[2-3-1]
[3-1-2]
[3-2-1]

grtz
Edited.

Posted: Tue Aug 15, 2006 1:10 am
by bungytheworm
Morning Seb.

I just wake up so im not 100% sure what youre after.

Code: Select all

DIM AS String Word, Letters()
DIM AS Integer Counter

LINE INPUT "Give in word: ";Word
  REDIM Letters(LEN(Word))

PRINT "Wordlenght is "; LEN(word)

FOR Counter = 1 to LEN(Word)
     Letters(Counter) = MID$(Word, Counter, 1)
NEXT

Posted: Tue Aug 15, 2006 1:14 am
by Seb McClouth
e.g. I have a word that is 'rta', you and I know that it would be 'art' or 'rat' but I want my program to show the following:

[1-2-3] = [r-t-a]
[1-3-2] = [r-a-t]
[2-1-3] = [t-r-a]
[2-3-1] = [t-a-r]
[3-1-2] = [a-r-t]
[3-2-1] = [a-t-r]

grtz

Posted: Wed Aug 16, 2006 12:06 am
by moneo
Seb,

I'm not an expert on this, but the numbers 123,132, etc. are a perfect set of the permutations of 3 numbers.

Since you didn't show us the PRINT statement, I don't know why you're printing the numbers of the letter positions instead of the letters themselves. My guess is that in order to print both the numbers and their corresponding letter, you probably need to keep 2 arrays.

The big problem that you will encounter later is when the input word contains duplicate letters, like HELLO which has 2 L's. The duplicate letters will generate duplicate permutations which you'll need to detect and eliminate. When you get to this part, let me know. I have an algorithm for this.

Good luck!

Regards..... Moneo

Posted: Wed Aug 16, 2006 9:05 am
by Quibbler
Anagram solver? Well for a N letter word there are N! permutations - far too many. I have written a similar program and the best approach is to search a dictionary file.
First check is the length, then if the anagram and a dictionary word have the same length use INSTR to check the letters are all there.

Posted: Wed Aug 16, 2006 4:25 pm
by Patz QuickBASIC Creations
Quibbler wrote:Anagram solver? Well for a N letter word there are N! permutations - far too many. I have written a similar program and the best approach is to search a dictionary file.
First check is the length, then if the anagram and a dictionary word have the same length use INSTR to check the letters are all there.
Although, if you used INSTR to find the letters, you would come up with duplicates... (like moneo said) You could remove letters from each string and still open your dictionary file.

Code: Select all

EXAMPLE: NOT CODE!
FREE and REEF are being tested.

FREE - REEF   (F is scanned and removed)
_REE - REE_   (R is scanned and removed)
__EE - _EE_   (One of the E's is scanned and removed)
___E - __E_   (The other E is scanned and removed)
____ - ____   (There are no more letters, the scan was a success)

Posted: Wed Aug 16, 2006 6:36 pm
by moneo
Quibbler wrote:Anagram solver? Well for a N letter word there are N! permutations - far too many. I have written a similar program and the best approach is to search a dictionary file.
First check is the length, then if the anagram and a dictionary word have the same length use INSTR to check the letters are all there.
Interesting approach, but where can you get such a dictionary file? To be used by a QB program, it would also have to be a plain ASCII text file.

*****

Posted: Thu Aug 17, 2006 1:42 am
by bungytheworm
I think its possible to get few most common words pretty easily.

Non native english person speaks good english if he knows 500 to 2K words.
Person who speaks english as hes/her home language, knows 2K to 10K words.

Here is first 850 http://www.langmaker.com/wordlist/basiclex.htm :lol:

Alltho, if i do remember right, ATM, english dictionary knows 200K words :lol:

Posted: Thu Aug 17, 2006 9:45 am
by Quibbler
I downloaded a word list about 12 years ago and amazingly the link is still there (with a 100 thousand extra words added)

http://www.dcs.shef.ac.uk/research/ilas ... words.html

I may even be able to find my Qbasic program that reads it. The program was actually to do those competitions of the type: - how many words can you make from "petes qb site is best".

Re: anagram solver

Posted: Fri Nov 01, 2019 8:14 am
by Bisser
Hello,
Do you know an online Anagram Solver ?