I remember in third grade the teacher spending seemly endless amount of
time explaining division. Divisor. Dividend. Remainder. I can't remember
all the names. Then the mechanics of actually doing the division. It is
surprising that all this arm waving and effort can be expressed by the
simple J expression

   divisor=.13
   dividend=.12345
   (0,divisor)#:dividend
949 8

Where 948 is the answer and 8 is the remainder.

On Thu, Jul 5, 2018 at 8:55 PM Skip Cave <[email protected]> wrote:

> Don,
>
> Wow! That's amazing!
>
> qr =.0 1#:]
>
> qr 13r5 136r44 38r13
>
> 2 3r5
>
> 3 1r11
>
> 2 12r13
>
> Thats way better than what I was trying. Thanks!
>
> Skip
>
> Skip Cave
> Cave Consulting LLC
>
>
> On Thu, Jul 5, 2018 at 9:48 PM Don Guinn <[email protected]> wrote:
>
> >    0 1#:13r5
> > 2 3r5
> >
> > On Thu, Jul 5, 2018, 8:20 PM Skip Cave <[email protected]> wrote:
> >
> > > I find that the rational fractions capability in J comes in handy for
> > > various applications. However, It occasionally comes in handy to be
> able
> > to
> > > convert a rational fraction into an integer and a remainder fraction. I
> > put
> > > together a function 'qr' (quotient/remainder) to input pure rational
> > > fractions and output integer - fraction representations.
> > >
> > > Here's the function:
> > >
> > > qr=. 3 : '(<.%/a),(1{a)%~|~/a=.2&x:y'
> > >
> > >
> > > Trying it out:
> > >
> > >    qr 13r5
> > >
> > > 2 3r5
> > >
> > > qr 136r44
> > >
> > > 3 1r11
> > >
> > > qr 38r13
> > >
> > > 2 12r13
> > >
> > > My qr function is pretty kludgy. Is there a shorter, more tacit
> version I
> > > could use? Also can it be made to operate on a vector of rational
> > > fractions, to give a 2xn matrix of integer/fraction results?
> > >
> > >    qr 13r5 136r44 38r13
> > >
> > > 2 3r5
> > >
> > > 3 1r11
> > >
> > > 2 12r13
> > >
> > > Skip
> > >
> > > Skip Cave
> > > Cave Consulting LLC
> > > ----------------------------------------------------------------------
> > > 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