Joseph Wetherell on Sat, 25 Jun 2016 18:26:07 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Need permutation help for n!/(n-r)!


One Jun 25, 2016 5:07 AM, "Bill Allombert" <Bill.Allombert@math.u-bordeaux.fr> wrote:
>
> On Sat, Jun 25, 2016 at 09:21:37AM +0530, chandra sekaran wrote:
> > numtoperm(n,k) will give  k-th permutation for n!.
> >
> > Any function for n!/(n-r)! available?
> >
> >
> > For n!/(n-r)!, Let n = 50 and r = 3.
> > If we define r as subset say [2,3,5] i want
> > calculate the number where [2,3,5] occur and reverse also.
> >
> > Any direct function available and if not how to calculate.
>
> You can use forvec(...,2)
>
> forvec(v=vector(3,i,[1,50]),print(v),2)
>
> Cheers,
> Bill

Use forvec(...,2) if you want to enumerate subsets 1..n of size r.  If you want all permutations of the subsets, then you can either obtain the subsets as above and then list the permutations in an inner loop, or you can use something like the following:

n=50
r=3
forvec(v=vector(r,i,[1,n]), if(length(Set(v))==r, print(v)))

Cheers,
Joe