RosettaCodeData/Task/Combinations/Picat/combinations-1.picat

13 lines
276 B
Text
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
go =>
% Integers 1..K
N = 3,
K = 5,
printf("comb1(3,5): %w\n", comb1(N,K)),
nl.
% Recursive (numbers)
comb1(M,N) = comb1_(M, 1..N).
comb1_(0, _X) = [[]].
comb1_(_M, []) = [].
comb1_(M, [X|Xs]) = [ [X] ++ Xs2 : Xs2 in comb1_(M-1, Xs) ] ++ comb1_(M, Xs).