The prolog code is:
find_in_list(Element,List,Count):-
findall(X,(member(X,List),X=Element),Output),
length(Output,Count).
split_list([],_,_).
split_list([H|T],ListAtL1,ListAtL2):-
split_list(T,NewListAtL1,ListAtL2),
not(member(H,ListAtL1)),
append(H,ListAtL1,NewListAtL1),
find_in_list(H,[H|T],Count),
Count is 1.
split_list([H|T],ListAtL1,ListAtL2):-
split_list(T,NewListAtL1,NewListAtL2),
not(member(H,ListAtL1)),
not(member(H,ListAtL2)),
append(H,ListAtL1,NewListAtL1),
append(H,ListAtL2,NewListAtL2),
find_in_list(H,[H|T],Count),
Count is 2.
and the result is:
?- split_list([a,a,1,2,3,1,3],ListAtL1,ListAtL2).
false.
But it should be:
?- split_list([a,a,1,2,3,1,3],ListAtL1,ListAtL2).
ListAtL1=[a,1,2,3],
ListAtL2=[a,1,3].
Why this happens?