• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

[Prolog] List combination start

pktbci

Junior Member
Hi all!

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).
For example, if you enter combination(2,[1,2,3,4],L), the result is:
Code:
L = [1, 2] ;
L = [1, 3] ;
L = [1, 4] ;
L = [2, 3] ;
L = [2, 4] ;
L = [3, 4]
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:
Code:
L = [1, 4] ;
L = [2, 3] ;
L = [2, 4] ;
L = [3, 4]
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!
 
Back
Top