[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference thebay::joyoflex

Title:The Joy of Lex
Notice:A Notes File even your grammar could love
Moderator:THEBAY::SYSTEM
Created:Fri Feb 28 1986
Last Modified:Mon Jun 02 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:1192
Total number of notes:42769

135.0. "word permutation program?" by DYO780::DYSERT () Thu Jan 09 1986 10:20

I thought I read a note about a program that generates all permutations
of a word, but I haven't been able to find it.  (For example, input a word,
say, ABE, and the program generates all "words" ABE, AEB, BAE, BEA, EAB,
EBA.)  Does anyone have a program that does this, preferably in BASIC?  Thanks.

	Barry
T.RTitleUserPersonal
Name
DateLines
135.1HYDRA::THALLERThu Jan 09 1986 11:4723
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
135.2DR::BLINNSun Jan 12 1986 23:3113
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
135.3DYO780::DYSERTMon Jan 13 1986 09:456
No.  I was looking for exactly what .1 gave me, namely a program that
generates all permutations of the word's letters.  A very nice solution;
I'll just have to change it since the target machine will not handle
the recursion.  Thanks!

	Barry