Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Fun with local database engine
Message
From
21/10/2005 13:45:58
Walter Meester
HoogkarspelNetherlands
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Other
Title:
Fun with local database engine
Miscellaneous
Thread ID:
01061182
Message ID:
01061182
Views:
67
Just some friday afternoon fun.

The following is a program to make words out of anagrams.
You need a english dictionary in a txt file. For example the one from:
http://aima.cs.berkeley.edu/data/wordlist
FUNCTION anagrams
LPARAMETERS cWord

IF !USED("Words")
	CREATE CURSOR Words (Word C(30))
	APPEND FROM c:\wordlist.txt CSV
	INDEX ON Word TAG Word
ENDIF

USE IN SELECT("Result")
SELECT 0 
CREATE CURSOR Result (Word C(30))
INDEX ON Word TAG Word

SELECT Words
nSec = SECONDS()
DO FindAnagram WITH "", LOWER(cWord), LEN(cWord)
? SECONDS() - nSec

SELECT Result
BROWSE NORM
RETURN

*-

FUNCTION FindAnagram
LPARAMETERS cPrefix, cRestWord, nLen
LOCAL nT, cChars, cAddChar

cChars = ""
caddChar = LEFT(cRestWord,1)

FOR nT = 1 TO nLen
	IF NOT(cAddChar $ cChars) AND KEYMATCH(cPRefix+LEFT(cRestWord,1)) AND ;
		((nLen = 2 AND KEYMATCH(cPRefix+cRestWord) AND !KEYMATCH(cPRefix+cRestWord+" ",1,"Result") ;
		OR !FindAnagram(cPrefix+LEFT(cRestWord,1), SUBSTR(cRestWord,2), nLen - 1))) 

		INSERT INTO Result VALUES (cPRefix+cRestWord)
	ENDIF
	cChars = cChars + cAddChar
	cAddChar = RIGHT(cRestWord,1)
	cRestWord = LEFT(RIGHT(cRestWord,1)+cRestWord, nLen)
ENDFOR
RETURN
Then you can call this with

DO anagrams WITH "ospon"
Reply
Map
View

Click here to load this message in the networking platform