kdb - How to implement combinations of a list -
all
i need combinations , permutations of list.
a function have been implemented permutations.
perm:{[n;l]$[n=1;l;raze .z.s[n-1;l]{x,/:y except x}\:l]} however, have no idea combinations, this:
l: 1 2 3 comb[2;l] 1 2 1 3 2 3 l: 1 2 3 4 comb[3;l] 1 2 3 1 2 4 1 3 4 2 3 4 thanks!
from solution, can do:
q)comb:{[n;l]$[n=1;l;raze .z.s[n-1;l]{x,/:y y>max x}\:l]} q)comb[2;1 2 3] 1 2 1 3 2 3 another approach using over:
q)perm:{{raze x{x,/:y except x}\:y}[;y]/[x-1;y]} q)comb:{{raze x{x,/:y y>max x}\:y}[;y]/[x-1;y]}
Comments
Post a Comment