Combinatorics

comb=: [:;(,.&.><@:>:@;\.)^:(i.@>:@-~`[`(1:<@i.@{.~<:@-,2:))

m comb n generates all possible choices of m elements from i.n

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
)

An equivalent verb from the for. page of the J dictionary.

Phrases/Statistics (last edited 2008-12-08 10:45:46 by )