This is a follow up to this question:
Generate all "unique" subsets of a set (not a powerset)
My problem is the same, but I think there might be a more optimized solution when order of items in the new subsets and across the subsets needs to be preserved.
Example:
[1, 2, 3]
Would result in:
[[1], [2], [3]]
[[1, 2], [3]]
[[1], [2, 3]]
[[1, 2, 3]]
I’ve already answered this question for Python, so I quickly ported my solution over to Ruby:
See my other answer for a complete explanation of how and why this works.