from http://c2.com/cgi/wiki?CodingProblem
Given K, answer an ordered collection of K ordered collections of size
approximately N / K, such that the first contains the first N / K
objects, the second the second N / K, etc.
There is a J solution on that page but it doesn't work in all cases.
Following is my solution (with one issue though):
c=: [: <. [ %~ [: # ]
hd=: ([: <: [) * c
b1=: hd {.]
b2=: hd }.]
f=: <@b2 ,~ [EMAIL PROTECTED] <\ b1
assert (0 1 2;3 4 5;6 7 8)-:3 f i.9
assert ((,:0);1 2)-:2 f i.3
assert (0 1 2;3 4 5;6 7 8 9)-:3 f i.10
assert ((0$<''),<0 1)-: 1 f i.2 NB. $ > 1 f i.2 is 1 2, not 2
as I expected
I don't like the last line -- that problem occurs once in a while. How
could I make it to pass "assert (<0 1)-:1 f i.2" with a simple
modification?
I am interested in seeing other J solutions.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm