anagram solver

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
User avatar
Seb McClouth
Veteran
Posts: 342
Joined: Wed Nov 09, 2005 7:47 am
Location: Inside the Matrix...
Contact:

anagram solver

Post 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.
QBinux is a Linux distribution with the aim of integrating the work of the vast community of free software developers at Pete's QBASIC Site in order to create a modern, performant, safe and easy to use system for system administrators and desktop users.
bungytheworm
Veteran
Posts: 288
Joined: Sat Feb 18, 2006 4:02 pm

Post 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
User avatar
Seb McClouth
Veteran
Posts: 342
Joined: Wed Nov 09, 2005 7:47 am
Location: Inside the Matrix...
Contact:

Post 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
QBinux is a Linux distribution with the aim of integrating the work of the vast community of free software developers at Pete's QBASIC Site in order to create a modern, performant, safe and easy to use system for system administrators and desktop users.
moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico

Post 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
User avatar
Quibbler
Coder
Posts: 16
Joined: Tue Jan 24, 2006 7:29 am
Location: Trinidad and Tobago

Post 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.
Patz QuickBASIC Creations
Veteran
Posts: 399
Joined: Wed Mar 02, 2005 9:01 pm
Location: Nashville, Tennessee
Contact:

Post 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)
moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico

Post 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.

*****
bungytheworm
Veteran
Posts: 288
Joined: Sat Feb 18, 2006 4:02 pm

Post 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:
User avatar
Quibbler
Coder
Posts: 16
Joined: Tue Jan 24, 2006 7:29 am
Location: Trinidad and Tobago

Post 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".
Bisser
Newbie
Posts: 1
Joined: Fri Nov 01, 2019 7:45 am

Re: anagram solver

Post by Bisser »

Hello,
Do you know an online Anagram Solver ?
Post Reply