Guys,
looking at some old code I had I found this function, which gives you all
the possible combinations of k elements from a lis of n objects. For
example:
<hansl>
function matrix choose(matrix from, scalar h)
if h <= 0
ret = {}
elif h == 1
matrix ret = vec(from)
else
ret = {}
from = vec(from)
n = rows(from)
loop i = 1 .. n-h+1 --quiet
x = from[i]
matrix c = selifr(from, (seq(1,n)' .> i))
if rows(c) > 0
matrix ret |= x ~ choose(c, h-1)
endif
endloop
endif
return ret
end function
eval choose(seq(1,4), 2)
</hansl>
returns
<output>
1 2
1 3
1 4
2 3
2 4
3 4
</output>.
My question is: I was under the impression that we alreasy added something
like this, but I can't find it either among the native functions, nor in
the extra package. Any hint?
-------------------------------------------------------
Riccardo (Jack) Lucchetti
Dipartimento di Scienze Economiche e Sociali (DiSES)
Università Politecnica delle Marche
(formerly known as Università di Ancona)
r.lucchetti(a)univpm.it
http://www2.econ.univpm.it/servizi/hpp/lucchetti
-------------------------------------------------------