Given the input array
[a,b,c,d,e]
and a 'join' function (a,b) => (a+b)
my code returns the following array of arrays, containing each possible variation obtained by applying the join function to various pairs of elements whilst maintaining the order:
[
[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],
]
Visually, what I'm trying to do is this:
The code works but I have no idea what to call it - and would like to use a name that other developers familiar with this operation will understand, should such a name exist. It's not a power set but it is something similar... does this particular set/array operation have a name?
EDIT: OK. They're not permutations; permutations would all be 5-element arrays in different orders [[a,b,c,d,e], [e,d,c,b,a], [a,d,b,c,e], ...]
They're not partitions, since any subset can only contain adjacent elements of the input. - in other words, partitions would allow this:
(This probably arises from pure set theory having no notion of an ordered set.)
They're not combinations since every element of the output uses every member of the input set exactly once.
I think myArray.OrderedPartitions((a,b) => (a+b))
is probably a suitably succinct and explanatory.
[a+b+c+d+e]
is missing? – Decisive[ a+b, c+d, e ]
). – Unify1+1+1+1+1 1+1+1+2 1+1+2+1 1+1+3 1+2+1+1 1+2+2 ...
– Baun