Re: Permutation Handler
Re: Permutation Handler
- Subject: Re: Permutation Handler
- From: Michelle Steiner <email@hidden>
- Date: Thu, 15 Feb 2001 09:24:31 -0800
On 2/15/01 8:58 AM, Arthur J Knapp <email@hidden> wrote:
>
> given a list: {1,2,3,4}
>
>
>
> the handler would return a list of all 24 possibilities:
>
>
>
> {{1,2,3,4},{1,2,4,3},{1,3,2,4},{1,3,4,2},{1,4,2,3},{1,4,3,2},{2,1,3,4},{2,1,
>
> 4,3},{2,3,1,4},{2,3,4,1},...}
>
>
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
>
copy lst to lst -- don't pass ref/data share
>
repeat with i from x to length of lst
>
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
It returns only twelve of the twenty four, twice each.
{{1, 2, 4, 3}, {1, 2, 4, 3}, {1, 3, 4, 2}, {1, 3, 4, 2}, {1, 4, 3, 2},
{1, 4, 3, 2}, {2, 1, 4, 3}, {2, 1, 4, 3}, {2, 3, 4, 1}, {2, 3, 4, 1}, {2,
4, 3, 1}, {2, 4, 3, 1}, {3, 1, 4, 2}, {3, 1, 4, 2}, {3, 2, 4, 1}, {3, 2,
4, 1}, {3, 4, 2, 1}, {3, 4, 2, 1}, {4, 1, 3, 2}, {4, 1, 3, 2}, {4, 2, 3,
1}, {4, 2, 3, 1}, {4, 3, 2, 1}, {4, 3, 2, 1}}
--Michelle
----------------------------------------------------------------------
| Michelle Steiner | We're not human beings having a spiritual |
| | experience. We're spiritual beings |
| email@hidden | having a human experience. |
----------------------------------------------------------------------