Re: Permutation Handler
Re: Permutation Handler
- Subject: Re: Permutation Handler
- From: "Arthur J Knapp" <email@hidden>
- Date: Thu, 15 Feb 2001 14:13:24 -0500
>
Date: Thu, 15 Feb 2001 09:18:02 -0800
>
Subject: Re: Permutation Handler
>
From: Jed Verity <email@hidden>
>
That's genius, man! However, it would appear that this handler actually only
>
generates half of the possible permutations (with a duplication of the first
>
half). See the results of {1,2,3} using permutateList:
>
>
{{1, 3, 2}, {1, 3, 2}, {2, 3, 1}, {2, 3, 1}, {3, 2, 1}, {3, 2, 1}}
i am so sorry :(
"Always test before you post, always test before you post..." !!!
>
I tried to go in and make adjustments but my brain was quickly scrambled.
>
Any further insights would be GREATLY appreciated.
This line:
>
> copy lst to lst -- don't pass ref/data share
should have been *inside* the repeat handler:
set integerList to {1, 2, 3, 4}
set thePermutations to {} -- collect them in here
permutateList(integerList, 1, thePermutations)
thePermutations
-- > {{1, 2, 4, 3}, {1, 2, 4, 3}, ...
on permutateList(lst, x, col)
if (x = length of lst) then
set end of col to lst
else
repeat with i from x to length of lst
copy lst to lst -- don't pass ref/data share
set {lst's item x, lst's item i} to ,
{lst's item i, lst's item x}
permutateList(lst, x + 1, col)
end repeat
end if
end permutateList
"would someone please check my work", he said sheepishly...
--
{
Arthur J Knapp, of STELLARViSIONs ;
http://www.STELLARViSIONs.com ;
mailto:email@hidden ;
"...well the rain falls down
without my help, I'm afraid
and my lawn gets wet,
though I withheld my consent..."
}