Edit:
I need to implement composition algorithm in Javascript, where the result would be the same as the figure on the right in Wikipedia.With a given number (n), the function would be able to return all possible separations, e.g.
2: [1,1], [2] (2 sets)
3: [1,1,1], [1,2], [2,1], [3] (4 sets)
4: [1,1,1,1], [1,1,2], [1,2,1], [2,1,1], [2,2], [3,1], [1,3], [4] (8 sets)
Ideally it should be a function accept and execute callback 2^(n-1) times. I will accept answers in any language I could understand (and rewrite from). Thanks!
Prusswan might have already given the best answer (the name of the algorithm), but I couldn’t resist writing some javascript: