This code generates all "sequential partitions" of a list:
testlist = {a, b, c, d, e};
w = Length[testlist];
breakpoints = Map[Join[#, {w}] &, Subsets[Range[w - 1]]];
partitionfrombreakpoints[breakpointlist_] :=
Prepend[Map[
Take[testlist, {breakpointlist[[#]] + 1,
breakpointlist[[# + 1]]}] &,
Range[Length[breakpointlist] - 1]],
Take[testlist, {1, breakpointlist[[1]]}]];
Print[Grid[Map[partitionfrombreakpoints, breakpoints]]];
Like so:
{a,b,c,d,e}
{a} {b,c,d,e}
{a,b} {c,d,e}
{a,b,c} {d,e}
{a,b,c,d} {e}
{a} {b} {c,d,e}
{a} {b,c} {d,e}
{a} {b,c,d} {e}
{a,b} {c} {d,e}
{a,b} {c,d} {e}
{a,b,c} {d} {e}
{a} {b} {c} {d,e}
{a} {b} {c,d} {e}
{a} {b,c} {d} {e}
{a,b} {c} {d} {e}
{a} {b} {c} {d} {e}
I have tried to use Partitions, SetPartitions, Compositions and Permutations to achieve the same result more elegantly, but without success. Can anyone help, please ?
Subsets[4]
? $\endgroup$ – rhermans Nov 6 '15 at 16:20