User:RE Boss/Performance Records/Combinations

From J Wiki
Jump to navigation Jump to search

This page gives the performances of the different verbs to determine all the combinations of size x from y , see the Combinations page.
All measurements are done wit x=10 and y=20 .

Place Verb relperf ret res Author
1  comb 2.34 1.17 2.00 Roger Hui
2  comb1 12.18 2.69 4.54 Roger Hui
0 (comb2 i.) 1.00 1.00 1.00 RE Boss

From Combinations

comb=: 4 : 0
 k=. i.>:d=.y-x
 z=. (d$<i.0 0),<i.1 0
 for. i.x do. z=. k ,.&.> ,&.>/\. >:&.> z end.
 ; z
)

comb1=: ((= +/"1) |.@:I.@# ]) #:@i.@(2&^)

comb2=: 4 : 0               NB.  invoke with x (comb2 i.) y
 d=. x-~#y
 k=. |.(>:d),\y
 z=. (d$<i.0 0),<i.1 0
 for_j. k  do. z=. j ,.&.> ,&.>/\. z end.
 ; z
)

From J602beta M.

combM=: 4 : 0 M.   NB. All size x combinations of i.y
 if. (x>:y)+.0=x do. i.(x<:y),x else. (0,.x comb&.<: y),1+x comb y-1 end.
)