Hi all!
I have this code:
For example, if you enter combination(2,[1,2,3,4],L), the result is:
Now I would like to enter something that allows you to start at a determined point of the combination. For example, something like: combination(2,[1,2,3,4],[1,4],L), and the result:
Starting the combination at [1,4] and skipping the "steps" [1,2] and [1,3].
But I don't know how to do it, and I don't have any idea...
Thanks for your help!
I have this code:
Code:
% combination(K,L,C) :- C is a list of K distinct elements
% chosen from the list L
combination(0,_,[]).
combination(K,L,[X|Xs]) :- K > 0,
el(X,L,R), K1 is K-1, combination(K1,R,Xs).
el(X,[X|L],L).
el(X,[_|L],R) :- el(X,L,R).
Code:
L = [1, 2] ;
L = [1, 3] ;
L = [1, 4] ;
L = [2, 3] ;
L = [2, 4] ;
L = [3, 4]
Code:
L = [1, 4] ;
L = [2, 3] ;
L = [2, 4] ;
L = [3, 4]
But I don't know how to do it, and I don't have any idea...
Thanks for your help!