How about:
3 2 4 (% * 0 ~: ]) 6 0 3
0.5 0 1.33333
On Fri, May 6, 2016 at 12:57 PM, Rob Hodgkinson <[email protected]> wrote:
> if you want to avoid the use of power ^: then just add 1 to y where y=0…
> x(%]+0=])y
> 0.5 2 1.33333
>
>
> > On 6 May 2016, at 10:53 AM, 'Pascal Jasmin' via Programming <
> [email protected]> wrote:
> >
> > I would go with first version. What don't you like about it?
> >
> >
> >
> >
> > ----- Original Message -----
> > From: Joe Bogner <[email protected]>
> > To: [email protected]
> > Sent: Thursday, May 5, 2016 8:47 PM
> > Subject: [Jprogramming] divide if not zero
> >
> > Given a list of numbers in x and y, what would be the simplest way to
> > divide x by y unless y is zero?
> >
> > I came up with these and I wasn't thrilled with any of them
> >
> > (3,2,4) %^:(0~:])"0 (6,0,3)
> >
> > 0.5 0 1.33333
> >
> >
> > (3,2,4) ]`%@.(0~:])"0 (6,0,3)
> >
> > 0.5 0 1.33333
> >
> >
> > It would be nice if it worked on x and y as atoms too
> >
> >
> > (5 divideExceptZero 0) -: 0
> >
> >
> > I suppose I could just replace the _ with 0 too, but that also seems
> > excessive
> >
> >
> > (3,2,4) ((0,]) {~ _ ~: ])@% (6,0,3)
> >
> > 0.5 0 1.33333
> >
> >
> > but it does work with atoms:
> >
> >
> > divideExceptZero =: ((0,]) {~ _ ~: ])@%
> >
> >
> > (5 divideExceptZero 0) -: 0
> >
> > 1
> > ----------------------------------------------------------------------
> > 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