RosettaCodeData/Task/Ordered-partitions/Mathematica/ordered-partitions-1.math

4 lines
237 B
Text
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
w[partitions_]:=Module[{s={},t=Total@partitions,list=partitions,k}, n=Length[list];
While[n>0,s=Join[s,{Take[t,(k=First[list])]}];t=Drop[t,k];list=Rest[list];n--]; s]
m[p_]:=(Sort/@#)&/@(w[#,p]&/@Permutations[Range@Total[p]])//Union