I assume(d) the collections are all size K, except the last one which has
size at least K.
An other solution which I prefer above the first idea, together with two
special cases.
3 (((<:@<[EMAIL PROTECTED] 0&>.@<. (<[EMAIL PROTECTED] i.)) #) </. ])
(65+i.10){a.
+---+---+----+
|ABC|DEF|GHIJ|
+---+---+----+
3 (((<:@<[EMAIL PROTECTED] 0&>.@<. (<[EMAIL PROTECTED] i.)) #) </. ])
(65+i.2){a.
+--+
|AB|
+--+
1 (((<:@<[EMAIL PROTECTED] 0&>.@<. (<[EMAIL PROTECTED] i.)) #) </. ])
(65+i.10){a.
+-+-+-+-+-+-+-+-+-+-+
|A|B|C|D|E|F|G|H|I|J|
+-+-+-+-+-+-+-+-+-+-+
R.E. Boss
-----Oorspronkelijk bericht-----
Van: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Namens Pascal Jasmin
Verzonden: woensdag 15 november 2006 14:51
Aan: Programming forum
Onderwerp: Re: [Jprogramming] Re: Coding Problem
My version of RE's general idea...
where the client spec is modularized because its not completely clear how to
proceed. (im assuming cutoff box size is k%2)
joinlast2 =: (>@:(_2&{) , >@:{:)
clientspec=: (_2&}. ,<@: joinlast2)[EMAIL PROTECTED](( -:@:#@:>@:(_2&{)) <
#@:>@:{:)
clientspec _6 (<\ i.) 15
+-----------+----------------------+
|0 1 2 3 4 5|6 7 8 9 10 11 12 13 14|
+-----------+----------------------+
clientspec _6 (<\ i.) 16
+-----------+-------------+-----------+
|0 1 2 3 4 5|6 7 8 9 10 11|12 13 14 15|
+-----------+-------------+-----------+
----- Original Message ----
From: R.E. Boss <[EMAIL PROTECTED]>
To: Programming forum <[email protected]>
Sent: Wednesday, November 15, 2006 8:30:43 AM
Subject: RE: [Jprogramming] Re: Coding Problem
Even a first shot can be more elegant
_3 ((*@|@|#) (]`(_2:(}.,[:,&.>/{.)])@.[) <\) i.10
+-----+-----+-------+
|0 1 2|3 4 5|6 7 8 9|
+-----+-----+-------+
R.E. Boss
-----Oorspronkelijk bericht-----
Van: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Namens R.E. Boss
Verzonden: woensdag 15 november 2006 12:34
Aan: 'Programming forum'
Onderwerp: RE: [Jprogramming] Re: Coding Problem
A first shot: use (-K) <\ i.N and append the content of the last two boxes
if the last one is a shard.
_3 ((*@|@|#) (]`(_2&}.,[:,&.>/_2&{.)@.[) <\) i.10
+-----+-----+-------+
|0 1 2|3 4 5|6 7 8 9|
+-----+-----+-------+
R.E. Boss
-----Oorspronkelijk bericht-----
Van: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Namens June Kim
Verzonden: woensdag 15 november 2006 6:17
Aan: Programming forum
Onderwerp: [Jprogramming] Re: Coding Problem
One more solution:
cs=: [: <. [ %~ [: # ]
b1=: 0 = cs | ]
b2=: ] < [ * cs
f=: (b1*.b2) < ;. 1 ]
2006/11/15, June Kim <[EMAIL PROTECTED]>:
> 2006/11/15, June Kim <[EMAIL PROTECTED]>:
> > 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?
>
> In other words, assert (,:<0 1)-: 1 f i.2
>
> Hm... Maybe I was wrong.
>
> My solution's result is more consistent than how I wanted the result to
be.
>
> The return value of f is, an array of rank 1. Each item of the array
> is of rank 1. Then my previous solution is more consistent.
>
> I am sometimes confused(and make mistakes) with the fact that in J we
> have scalars of which rank is empty, which is different from a rank-1
> array of a single item. Even a boxed value can a scalar or a rank-1
> array(say <1 and ,:<1).
>
> >
> > I am interested in seeing other J solutions.
> >
>
> Still.
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm