Re: UnrankPermutation newbie problem .. Combinatorica Package
- To: mathgroup at smc.vnet.net
- Subject: [mg49978] Re: UnrankPermutation newbie problem .. Combinatorica Package
- From: BV <dont at bug.me>
- Date: Mon, 9 Aug 2004 04:29:16 -0400 (EDT)
- References: <cf22sg$7tf$1@smc.vnet.net> <cf4t32$lid$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
BV wrote: > BV wrote: > > >>I found that calling NthPermutation via MathLink in C++ is rather costly >> for my purposes, therefore I'm inquiring to re-write the function >>entirely in C++. I hope by eliminating unnecessary calls to MathLink >>this would speed up my program significantly. >> >>As, I admit, I am not very versed in Mathematics itself can anyone point >>me in the direction where to start; how this function works; what >>formula is used, etc. >>Thank you >> > > I found in the "combinatorica.m" file that this function is obsolete and > that UnrankPermutation[] function should be used instead. This is the > code as it should work (from the "combinatorica.m" file): > > UnrankPermutation[r_Integer, {}] := {} > UnrankPermutation[r_Integer, l_List] := > Module[{s = l, k, t, p = UP[Mod[r, Length[l]!], Length[l]]}, > Table[k = s[[t = p[[i]] ]]; > s = Delete[s, t]; > k, > {i, Length[ p ]} > ] > ] > > UnrankPermutation[r_Integer, n_Integer?Positive] := > UnrankPermutation[r, Range[n]] > > Can someone please write this as an algorithm or a formula as I don't > have any books on Mathematica and this looks complicated; a plain > formula for this would do! > I've just solved it no help needed anymore :)