Here are the canonicalized partitions generated directly in lexicographic
order:

cnext=:3 : 0
inc=.(2 </\ y)*.}: -. ~: y
if. 0=+/inc do. /:~ y return. end.
last  =.inc i: 1
(last {. y), nexts last }. y
)

nexts=:3 : '({.,/:~@:}.) ( y i. <./ @: (#~ (>{.)) y) swap y'

swap=:4 : 'y {~ C. (0,x);<:#y'

   cnext^:(i.15) 0 0 1 1 2 2
0 0 1 1 2 2
0 0 1 2 1 2
0 0 1 2 2 1
0 1 0 1 2 2
0 1 0 2 1 2
0 1 0 2 2 1
0 1 1 0 2 2
0 1 1 2 0 2
0 1 1 2 2 0
0 1 2 0 1 2
0 1 2 0 2 1
0 1 2 1 0 2
0 1 2 1 2 0
0 1 2 2 0 1
0 1 2 2 1 0

Best wishes,

John

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to