Test Case
?- decompose([[1,2,8],[3,4],[5,6]], L1, L2).
L1 = [1,3,5], L2 = [[2,8],[4],[6]] ? ;
no
I had tried another implementation however the feedback given was that it was inefficient.
The inefficient implementation
listFirst([], []).
listFirst([H1|T1], [H2|Z]):-
H1 = [H2|_],
listFirst(T1, Z).
listFollowers([], []).
listFollowers([H1|T1], [T2|Z]):-
H1 = [H2|T2],
listFollowers(T1, Z).
decompose(A,L1,L2) :-
listFollowers(A, L2),
listFirst(A, L1).