I have a number, let's say 123, and I want to generate a set of all the possible ways to split it:
[[1, 23], [12, 3], [1, 2, 3]].
I have thought of creating the powerset of [1,2,3]:
?- findall(Powerset, powerset([1,2,3], Powerset), Z).
Z = [[1], [1, 2], [1, 2, 3], [2], [2, 3], [3]].
then combining the sets together and checking with append/3
if their concatenation is the initial set [1,2,3], i.e
[[1], [2, 3]] -> [1, 23]
[[1, 2], [3]] -> [12, 3]
[[1], [2], [3]] -> [1, 2, 3]
Do you think of another simpler (more elegant) solution?
I use this predicate from gnu Prolog powerset modification
powerset(L, [H|T]):-
append([H|T], _, L).
powerset([_|L], P):-
powerset(L, P).