| The following program runs in VAX BASIC V2.4 It uses recursion so it won't
run on all BASICs, although it is modifyable.
5 rem program prints out permutation of input string. Kurt Thaller.
10 input"word to be permuted: ";a$
20 prefix$=""
30 call permute(prefix$,a$)
35 total=1
40 for I= 2 to len(a$)
50 total=total*I
60 next I
70 print"a total of ";total;" words."
80 end
100 sub permute (pre$,in$)
110 if len(in$)=1 then print pre$;in$
120 exit sub if len(in$)=1
130 for x = 1 to len(in$)
140 prefix$=pre$+mid$(in$,x,1)
150 remainder$=left$(in$,x-1)+right$(in$,x+1)
160 call permute(prefix$,remainder$)
170 next x
180 subend
200 end
|
| I believe you're looking for one of Eric Osman's contributions. He
wrote a program that took his word lists, and for each word, he put
out a record with the characters of the word sorted, followed by the
original text of the word. He sorted the resulting file, and then
piped it through a program that dumped out the matches where there
was more than one matching first part. This did not give all the
permutations, just the sets of words that are permutations of one
another.
You'll find his list of interesting results, as well as explanation,
in topic # 50, "Anagrams (smargana)".
Tom
|