[seqfan] Re: next partition into distinct parts
Alois Heinz
heinz at hs-heilbronn.de
Mon Feb 14 04:31:39 CET 2011
Here is a Maple program for this problem. Perhaps someone can
translate it into Mathematica language?
# first partition of n into distinct parts
# with largest part <=i or 0 if not defined
b:= proc(n,i) option remember;
if n<0 then 0
elif n=0 then []
elif i=0 then 0
elif b(n-i,i-1)<>0 then [i,(b(n-i,i-1)[])]
elif b(n, i-1)<>0 then b(n,i-1)
else 0
fi
end:
# next partition into distinct parts
# after given partiton L or 0 if not defined
a:= proc(L) local i, t;
t:= 0;
for i from nops(L) to 1 by -1 do
t:= t+L[i];
if b(t,L[i]-1)<>0 then
RETURN ([L[1..i-1][], b(t,L[i]-1)[]])
fi
od; 0
end:
a ([11,4,2]); # gives [11, 3, 2, 1]
Alois
Am 13.02.2011 07:13, schrieb David Newman:
> Does anyone out there have a Mathematica program which will give the
> next partition into distinct parts?
>
> For example given the partition {11 , 4 , 2} as input, it should
> output {11 ,3 ,2 , 1}.
More information about the SeqFan
mailing list