Oh...  I see...

I noticed that the ravel of the boxes did not match the original
sequence and did not look close enough after that.

Anyways, I guess here's how I would approach this:

reps=: 1+0,~0,2~:/\[:[^:(0~:[)/\.@:*2 -/\]
ud=: reps ((1,2 =/\ [ # #\@]) <;.1 #) ]

Thanks,

-- 
Raul

On Thu, May 20, 2021 at 10:42 AM R.E. Boss <r.e.b...@outlook.com> wrote:
>
> I thought it was clear from the output (therefore I used ?. in the testcases) 
> that the order of the input array should not be altered.
> That was the constraint you were missing.
>
>
> R.E. Boss
>
>
> -----Original Message-----
> From: Programming <programming-boun...@forums.jsoftware.com> On Behalf Of 
> Raul Miller
> Sent: donderdag 20 mei 2021 16:33
> To: Programming forum <programm...@jsoftware.com>
> Subject: Re: [Jprogramming] ups & downs
>
> I could use some additional details.
>
> I mean... it seems to me that Foo=:<@/:~ would minimally satisfy the 
> requirements which have been stated so far.
>
> But, presumably, there's some kind of "cost function" which we are trying to 
> minimize, and presumably that has something to do with how pairs are handled?
>
> Or, perhaps, you have a constraint that no more than three of any given 
> number may appear in any box, and I think I see a constraint that adjacent 
> boxes must alternate their order. But perhaps there are also similar 
> additional metrics or constraints?
>
> Thanks,
>
> --
> Raul
>
> On Thu, May 20, 2021 at 6:43 AM R.E. Boss <r.e.b...@outlook.com> wrote:
> >
> > Given an array of numbers, like
> >
> >    ?.@#~20
> > 14 16 8 6 5 8 6 16 16 19 13 12 3 1 9 12 17 0 9 5
> >
> > there is always a sequence of (non-strict) ups & downs, like
> >
> >    14 16;16 8 6 5;5 8;8 6;6 16 16 19;19 13 12 3 1; 1 9 12 17;17 0;0
> > 9;9 5
> > +-----+--------+---+---+----------+------------+---------+----+---+---+
> > |14 16|16 8 6 5|5 8|8 6|6 16 16 19|19 13 12 3 1|1 9 12 17|17 0|0 9|9
> > |5|
> > +-----+--------+---+---+----------+------------+---------+----+---+---+
> >
> > Well, this is the way I prefer to have the ups & downs, where they share 
> > their border terms.
> > Which verb makes this transformation?
> > Elegance, as always, is appreciated, correctness is a must, efficiency a 
> > blessing.
> >
> > Some testcases:
> >
> >    Foo ?.@#~25
> > +----+---+---+-------+-----+-----+----+---+---+----+-------+----+----+-------+----+----+----+----+------+---+
> > |19 6|6 8|8 6|6 10 23|23 16|16 21|21 1|1 9|9 8|8 22|22 13 1|1 14|14
> > |2|2 17 20|20 9|9 15|15 7|7 22|22 4 2|2 9|
> > +----+---+---+-------+-----+-----+----+---+---+----+-------+----+----+-------+----+----+----+----+------+---+
> >    Foo ?.@#~30
> > +--------+------+----+--------+--------+---------+----+-----+-----+----+----+-----+-----+----+-------+-------+-------+--------+-----+-----+
> > |24 26 28|28 6 5|5 28|28 16 16|16 16 26|26 19 3 2|2 13|13 11|11 19|19
> > |2|2 27|27 10|10 19|19 5|5 17 27|27 19 7|7 24 28|28 27 14|14 22|22 21|
> > +--------+------+----+--------+--------+---------+----+-----+-----+----+----+-----+-----+----+-------+-------+-------+--------+-----+-----+
> >
> >
> > R.E. Boss
> > ----------------------------------------------------------------------
> > 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