If my earlier offering was on the right lines,
then this is an improvement, albeit a bit more
verbose.  Rather than take the floor of N%K,
it takes the nearest integer, so reducing the
deviation of fret-sizes.  These no longer
conform to the results of June kim's "f".

  4 ((>./\@([ {. <[EMAIL PROTECTED] # [EMAIL PROTECTED])~ #) </. ]) i.11
+---+---+---+----------+
|0 1|2 3|4 5|6 7 8 9 10|
+---+---+---+----------+
  4 ((>./\@([ {. (<.&.+.)@>:@% # [EMAIL PROTECTED])~ #) </. ]) i.11
+-----+-----+-----+----+
|0 1 2|3 4 5|6 7 8|9 10|
+-----+-----+-----+----+
  7 ((>./\@([ {. <[EMAIL PROTECTED] # [EMAIL PROTECTED])~ #) </. ]) i.11
+-+-+-+-+-+-+----------+
|0|1|2|3|4|5|6 7 8 9 10|
+-+-+-+-+-+-+----------+
  7 ((>./\@([ {. (<.&.+.)@>:@% # [EMAIL PROTECTED])~ #) </. ]) i.11
+---+---+---+---+---+--+
|0 1|2 3|4 5|6 7|8 9|10|
+---+---+---+---+---+--+
Mike

Mike Day wrote:
So does this satisfy your requirements?

  1 ((>./\@([ {. <[EMAIL PROTECTED] # [EMAIL PROTECTED])~ #) </. ]) i.10
+-------------------+
|0 1 2 3 4 5 6 7 8 9|
+-------------------+
  2 ((>./\@([ {. <[EMAIL PROTECTED] # [EMAIL PROTECTED])~ #) </. ]) i.10
+---------+---------+
|0 1 2 3 4|5 6 7 8 9|
+---------+---------+
  3 ((>./\@([ {. <[EMAIL PROTECTED] # [EMAIL PROTECTED])~ #) </. ]) i.10
+-----+-----+-------+
|0 1 2|3 4 5|6 7 8 9|
+-----+-----+-------+
  7 ((>./\@([ {. <[EMAIL PROTECTED] # [EMAIL PROTECTED])~ #) </. ]) i.10
+-+-+-+-+-+-+-------+
|0|1|2|3|4|5|6 7 8 9|
+-+-+-+-+-+-+-------+
It doesn't check the ordering of the input list. What should be
the result for 10?10 ? Compare
  3 ((((-@ <[EMAIL PROTECTED]  )~)#)<\])   q=: 0 1 8 2 6 7 9 4 5 3
+-----+-----+-------+
|0 1 8|2 6 7|9 4 5 3|
+-----+-----+-------+
  3 f q  NB. June Kim's "f" +-------+---------+-+
|0 1 8 2|6 7 9 4 5|3|
+-------+---------+-+

Mike

June Kim wrote:
Well, it doesn't work in the case of K=4 and N=10.

     (-<.10%4) ((*@|@|#) (]`(_2:(}.,[:,&.>/{.)])@.[) <\) i.10
+---+---+---+---+---+
|0 1|2 3|4 5|6 7|8 9|
+---+---+---+---+---+

They are five segments, instead of four(K). What actually it should return is:
  4 f i.10
+---+---+---+-------+
|0 1|2 3|4 5|6 7 8 9|
+---+---+---+-------+


2006/11/16, June Kim <[EMAIL PROTECTED]>:
2006/11/15, R.E. Boss <[EMAIL PROTECTED]>:
> A first shot: use (-K) <\ i.N and append the content of the last two boxes

It shouldn't be (-K) <\ i.N

K in the problem is the number of segments of the whole ordered list.
Therefore, it should've been <.N%K instead.

> 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
>

Thank you for your solution.


>
> -----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


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


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

Reply via email to