Created
October 27, 2021 08:58
-
-
Save k3ut0i/f3af68b6ed85149c4acaec8e1939492d to your computer and use it in GitHub Desktop.
combinations of elements from a list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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