Index   <<   >>

Nifty combos

   3517 A. 'senator'
treason
   3229 A. 'treason'
senator

All permutations of i.n

   (perm=. i.@! A. i.) 3
0 1 2
0 2 1
1 0 2
1 2 0
2 0 1
2 1 0

A recursive computation of all size m combinations of i.n .

comb  =. basisc`recurc @. testc
 testc  =. *@[ *. <
 basisc =. i.@(<: , [)
 recurc =. (countc # startc) ,. (indexc@countc{comb&.<:)
  startc =. i.@-.@-
  countc =. <:@[ ! <:@[ + |.@startc
  indexc =. ;@:((i.-])&.>)

   3 comb 4
0 1 2
0 1 3
0 2 3
1 2 3

A recursive computation of all size m partitions of n

part  =. basisp`recurp@.testp
 testp  =. 1&<@[ *. <
 basisp =. (0&<@] , [) $ (1&=@[ 1&>.@* ])
 recurp =. (maskp formp ])@(part&<:)
  maskp  =. startp <:/ {."1 <. -.@(-/)@(_2&{.)"1
   startp =. +/@{. >:@i.@<.@%&>: {:@$
  formp =. pfxp@[ decrp@,. indp@[ { ]
   pfxp  =. +/"1 # >:@i.@#
   decrp =. (>:@(-/)@(_1 0&{) _1} ])"1
   indp  =. , # */@$ $ i.@{:@$

   4 part 8
1 1 1 5
1 1 2 4
1 1 3 3
1 2 2 3
2 2 2 2