I am writing a function that returns distinct sublists of a size n.
When I run the following prolog code with a query gen_list_n(4,D,[1,2,3,4]) it runs into an infinite loop after returning the first answer. How do I prevent this?
member_rem(E,L,R) :-
append(X,Y,R),
append( X ,[E], L0),
append( L0,Y, L).
gen_list_n(0,[],_).
gen_list_n(N,[X|Xs],L) :-
N > 0,
N1 is N-1,
member_rem(X,L,R),
gen_list_n(N1,Xs,R).