• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Permutation Handler
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Permutation Handler


  • Subject: Re: Permutation Handler
  • From: "Arthur J Knapp" <email@hidden>
  • Date: Thu, 15 Feb 2001 11:58:10 -0500

> Date: Wed, 14 Feb 2001 00:09:45 -0800
> Subject: Permutation Handler
> From: Jed Verity <email@hidden>

> 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


--
{
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..."
}


  • Follow-Ups:
    • Re: Permutation Handler
      • From: Jed Verity <email@hidden>
  • Prev by Date: Re: Accessing a Record by variable--"the" solutions
  • Next by Date: Re: Permutation Handler
  • Previous by thread: Permutation Handler
  • Next by thread: Re: Permutation Handler
  • Index(es):
    • Date
    • Thread