metacard digest, Vol 1 #552 - 2 msgs
wouter
wouter.abraham at pi.be
Thu Mar 20 07:21:01 EST 2003
> Re: metacard digest, Vol 1 #552 - 2 msgs
>
> * From: John Vokey
> * Subject: Re: metacard digest, Vol 1 #552 - 2 msgs
> * Date: Tue, 18 Mar 2003 09:54:55 -0800
----- snip
> I like it: nice use of the decimal to binary conversion to implement
> my algorithm (i.e., 1/0 flags to indicate presence/absence of a given
> letter). Unfortunately, as with my version, it is not recursive, as
> was originally asked for. Furthermore, it requires the baseConvert
> function, not available in most other XTalks, including hypertalk, and
> it was in the hypercard list that I first saw the request.
>
> --
> John R. Vokey, Ph.D. |\ _,,,---,,_
> Professor /,`.-'`' -. ;-;;,_
> Department of Psychology and Neuroscience |,4- ) )-,_. ,\ ( `'-'
> University of Lethbridge '---''(_/--' `-'\_)
>
Ok a recursive one :^)))
on mouseUp
put perm(fld "orig") into fld "result"
end mouseUp
function perm factors, i, theresult
if i <> 0 then
put baseConvert(i, 10, 2) into b ### or put dec2Bin(i) into i for
the other xTalk users
put char 1 to (the length of factors) - the num of chars in b of
(char 2 to -1 of (10 ^ (the length of factors))) & b into b
repeat with j = 1 to (the length of factors)
if char j of b = 1 then put char j of factors after thecollector
end repeat
put thecollector & cr after theresult
get perm(factors, (i - 1) , theResult)
else if i = "" then
put 2 ^ (the length of factors) - 1 into i
get perm(factors, i , theResult)
else if i = "0" then
sort theresult
sort lines of theresult by number of chars in each
return theresult
end if
end perm
function dec2Bin x
repeat with i = 0 to x
if 2^i > x then exit repeat
end repeat
repeat with i = i - 1 down to 0
if x - 2^i >= 0 then
put 1 after binNum
put x - 2^i into x
else put 0 after binNum
end repeat
return binNum
end dec2Bin
Have a nice day
WA
More information about the metacard
mailing list