nl=:  ([ {~ I.+e.~)~ /:~     

This is going to fail if there are repeated elements in y.

   nl =. (<:@:I. { [)~ \:~

This is going to fail if all elements of y are the same
(I. will treat the list as ascending)

Workarounds are possible.

Henry Rich


> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Henry Rich
> Sent: Sunday, September 24, 2006 1:22 AM
> To: 'Programming forum'
> Subject: RE: [Jprogramming] Next larger and Last less
> 
> Guests arrived, wine was enjoyed... then I had an idea.
> Please forgive me if it's bogus:
> 
>    nl =. (<:@:I. { [)~ \:~ 
> 
>    x
> 6 10 8 4 9 7.5 11 5 5.5 9.5 3 5.5
>    y
> 2 2.5 3 3.5 5 5.5 7 7.5 11 11.5 13 13.5 17 17.5
>    x nl y
> 7 11 11 5 11 11 11.5 5.5 7 11 3.5 7
> 
> Henry Rich
> 
> 
> > -----Original Message-----
> > From: [EMAIL PROTECTED] 
> > [mailto:[EMAIL PROTECTED] On Behalf Of R.E. Boss
> > Sent: Saturday, September 23, 2006 6:09 PM
> > To: 'Programming forum'
> > Subject: RE: [Jprogramming] Next larger and Last less
> > 
> > Second try.
> > 
> > nle=: (I. { [)~  /:~        
> >     NB. next_larger_or_equal of x in y
> > nl=:  ([ {~ I.+e.~)~ /:~    
> >     NB. next_larger of x in y
> > 
> >    (('X ','nle',:'nl'),.@;'Y'),. X (([,nle,:nl),.@;/:[EMAIL PROTECTED])Y
> > +---+-----------------------------------------------+
> > |X  |6 10  8 4  9 7.5   11   5 5.5 9.5   3 5.5      |
> > |nle|7 11 11 5 11 7.5   11   5 5.5  11   3 5.5      |
> > |nl |7 11 11 5 11  11 11.5 5.5   7  11 3.5   7      |
> > +---+-----------------------------------------------+
> > |Y  |2 2.5 3 3.5 5 5.5 7 7.5 11 11.5 13 13.5 17 17.5|
> > +---+-----------------------------------------------+
> > 
> > lle=: (I. { [)~  \:~        
> >     NB. last_less_or_equal of x in y
> > ll=: ([ {~ I.+e.~)~  \:~
> >     NB. last_less of x in y
> > 
> >    (('X ','lle',:'ll'),.@;'Y'),. X (([,lle,:ll),.@;/:[EMAIL PROTECTED])Y
> > +---+-----------------------------------------------+
> > |X  |  6  10   8   4   9 7.5  11   5 5.5 9.5   3 5.5|
> > |lle|5.5 7.5 7.5 3.5 7.5 7.5  11   5 5.5 7.5   3 5.5|
> > |ll |5.5 7.5 7.5 3.5 7.5   7 7.5 3.5   5 7.5 2.5   5|
> > +---+-----------------------------------------------+
> > |Y  |2 2.5 3 3.5 5 5.5 7 7.5 11 11.5 13 13.5 17 17.5|
> > +---+-----------------------------------------------+
> > 
> > 
> > R.E. Boss
> > 
> > 
> > -----Oorspronkelijk bericht-----
> > Van: [EMAIL PROTECTED]
> > [mailto:[EMAIL PROTECTED] Namens Henry Rich
> > Verzonden: zaterdag 23 september 2006 21:37
> > Aan: 'Programming forum'
> > Onderwerp: RE: [Jprogramming] Next larger and Last less
> > 
> > I expect a different result:
> > 
> >    nl =. 4 : 't {~ s - x = s { t [ s =. t I. x [ t =. /:~ y'
> >    x nl y
> > 2.75138 3.44049 6.7335 8.84258
> >   
> > 
> > Henry Rich
> > 
> > > -----Original Message-----
> > > From: [EMAIL PROTECTED] 
> > > [mailto:[EMAIL PROTECTED] On Behalf Of 
> > Miller, Raul D
> > > Sent: Saturday, September 23, 2006 3:09 PM
> > > To: Programming forum
> > > Subject: RE: [Jprogramming] Next larger and Last less
> > > 
> > > Henry Rich wrote:
> > > > > Does your nl also work for non-integers?
> > > > Nope. 
> > > 
> > > It seems to work:
> > > 
> > >    nle =. (I. { [)~ /:~
> > >    nl =. (nle~ >:)~
> > >    x=. 2 3 5 7 +?.4#0
> > >    y=. 1+(?.~9)+?.9#0
> > >    x
> > > 2.65345 3.39622 5.44049 7.84258
> > >    y
> > > 4.65345 5.39622 3.44049 8.84258 9.20817 2.75138 6.7335 
> > 7.10353 1.39237
> > >    x nl y
> > > 4.65345 4.65345 6.7335 8.84258
> > > 
> > > What failure mode do you expect?
> > > 
> > > Or are you talking about the y >:&(>./) 1+x requirement?
> > > 
> > > Thanks,
> > > 
> > > -- 
> > > Raul
> > > 
> > > 
> > 
> ----------------------------------------------------------------------
> > > 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