home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
kermit.columbia.edu
/
kermit.columbia.edu.tar
/
kermit.columbia.edu
/
scripts
/
ckermit
/
permute
< prev
next >
Wrap
Text File
|
2004-01-19
|
1KB
|
46 lines
#!/usr/local/bin/kermit +
#
# With pleasure I implemented the string permutation in C-Kermit attached
# here. What C-Kermit can do is limited only by one's own imagination.
#
# Dat Thuc Nguyen
# 16 January 2004
#
# \%1 = String to be permuted
# \%2 = Length of current segment
#
define permute {
(let n \flength(\%1) cnt 0)
local recur
define recur {
if == \%2 n {
(++ cnt)
echo \flpad(\m(cnt),5). \%1
} else {
local i
for i \%2 n 1 {
if > i \%2 {
asg \%1 \fsubstr(\%1,1,\%2-1)\fsubstr(\%1,i,1)-
\fsubstr(\%1,\%2+1,i-\%2-1)\fsubstr(\%1,\%2,1)\fsubstr(\%1,i+1,\flen(\%1))
}
recur {\%1} \feval(\%2+1)
}
}
}
recur {\%1} 1
echo
}
echo Testing...
permute a # One letter
permute ab # Two letters
permute abc # Three
permute abcd # Four
echo To try it yourself type:
echo
echo { permute "word(s) of your choice"}
echo
END