Anagrams - Combinations/Perumatations

Blitz3D Forums/Blitz3D Beginners Area/Anagrams - Combinations/Perumatations

Okay, something like this:

Type originalLetter
	Field char$
	Field used
End Type
Global currentOriginalLetter.originalLetter=Null
Global currentDictionaryWord$=""



While True
	Cls : Locate 0,0
	For currentOriginalLetter=Each originalLetter
		Delete currentOriginalLetter
	Next

	original$=Lower(Input$("Enter a source word: "))
	originalLength=Len(original$)
	
	For i=1 To originalLength
		currentOriginalLetter = New originalLetter
		currentOriginalLetter\char$=Mid$(original$,i,1)
	Next

	Print
	Print "'"+original$+"' contains the following..."

	fileIn=ReadFile("exampleDict.txt")
	While Not Eof(fileIn)
		currentDictionaryWord$=ReadLine$(fileIn)
		If match() = True Then Print currentDictionaryWord$
	Wend
	CloseFile fileIn
	
	Print
	Print "<Any key>"
	WaitKey
Wend
End

Function match()
	Local failures=0
	For currentOriginalLetter=Each originalLetter
		currentOriginalLetter\used=False
	Next
	
	For i=1 To Len(currentDictionaryWord$)
		thisLetterMatched=False
		For currentOriginalLetter=Each originalLetter
			If Mid$(currentDictionaryWord$,i,1)=currentOriginalLetter\char$ And currentOriginalLetter\used=False
				thisLetterMatched=True
				currentOriginalLetter\used=True
			EndIf
			If thisLetterMatched=True Then Exit	
		Next
		If thisLetterMatched=False Then failures=failures+1
	Next
	
	If failures=0
		Return True
	Else
		Return False
	EndIf	
End Function


exampleDict.txt is just a text file containing...
hello
this
is
an
example
dictionary
with
one
entry
per
line
so
blitz
can
read
it
easily


So, for example, if you enter 'blitzbasic' as your source word you will get three results from the example dictionary... is, blitz & it. Not an anagram engine in itself, but it should help you build one.

EDIT: Can't help thinking that, rather than trying to reinvent the wheel based on all the incomplete ideas and code snips that we post, you should probably just reference an existing solution.