Skip to content

Instantly share code, notes, and snippets.

@k3ut0i
Created October 27, 2021 08:58
Show Gist options
  • Save k3ut0i/f3af68b6ed85149c4acaec8e1939492d to your computer and use it in GitHub Desktop.
Save k3ut0i/f3af68b6ed85149c4acaec8e1939492d to your computer and use it in GitHub Desktop.
combinations of elements from a list
cons(X, Y, [X|Y]).
comb(0, _, [[]]).
comb(N, Xs, []) :- length(Xs, N1), N > N1.
comb(N, [X|Xs], Ys) :-
N > 0,
N1 is N - 1,
comb(N, Xs, Ys1),
comb(N1, Xs, Ys2),
maplist(cons(X), Ys2, Ys3),
append(Ys1, Ys3, Ys).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment