C function in metaTalk?
john
jrvokey at vokbain.net
Mon Mar 17 04:17:18 EST 2003
Eric,
Although not recursive, this routine will provide for all possible
(i.e., 2^k-1) effects:
on test
put perm("abc") into fld "out"
end test
function perm factors
put the length of factors into numfac
repeat with c=1 to numfac
put 0 into item c of x
end repeat
put 1 into item 1 of x
put empty into effects
repeat while item numfac of x <2
put empty into table
repeat with c =1 to numfac
if item c of x=1 then put char c of factors after table
end repeat
if effects is not empty then put return after effects
put table after effects
put 1 into c
add 1 to item 1 of x
repeat while (item c of x>1) and (c<numfac)
put 0 into item c of x
add 1 to c
add 1 to item c of x
end repeat
end repeat
return effects
end perm
If you want the effects sorted by length, use this routine:
on test
put sortEffects(perm("abc")) into fld "out"
end test
function sortEffects effects
put the number of lines of effects into nl
if nl>1 then
repeat with i=1 to nl-1
repeat with j=i+1 to nl
if the length of line j of effects<the length of line i of
effects then
put line j of effects into t
put line i of effects into line j of effects
put t into line i of effects
end if
end repeat
end repeat
end if
return effects
end sortEffects
--
John R. Vokey, Ph.D. |\ _,,,---,,_
Professor /,`.-'`' -. ;-;;,_
Department of Psychology and Neuroscience |,4- ) )-,_. ,\ ( `'-'
University of Lethbridge '---''(_/--' `-'\_)
More information about the metacard
mailing list