Phrases/Statistics

From J Wiki
Jump to: navigation, search

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.