disjoint lists from 1 list.. looking for generic solution(N sublists)

08/03/2017 20:50 Buckyx#1
they should also preserve element order

eg. initial list = { 1, 2, 3, 4 }

2 sublists = [{ 1 }, { 2, 3, 4 }], [{ 1, 2 }, { 3, 4 }], [{ 1, 2, 3 }, { 4 }]
3 sublists = [{ 1 }, { 2 }, { 3, 4 }], [{ 1 }, { 2, 3 }, { 4 }], [{ 1, 2 }, { 3 }, { 4 }] etc

up to N sublists and all of them

I can come up with simple solution for N = 2 or 3 sublists but I need more of them. like 5 and would like to avoid bad code of generating each N separately

found a solution but its ugly as hell, just in case someone would like to solve this in the future