Yes. An easy way to find odd numbers. But 2&| works just as well. You might have noticed the thread wanting to change the definition of scalar&#: to have the same meaning as scalar&#.^:_1 . Not sure where that discussion will go, but your isOdd would fail if implemented.
On Fri, Jul 6, 2018 at 11:01 AM Skip Cave <[email protected]> wrote: > If I had read far enough down on the NuVoc page for Antibase (#:) I would > have found this: > > 3. Convert a number to quotient/remainder form > > 0 5 #: 26 NB. Quotient and remainder after dividing by 5 > 5 1 > 0 5 #: _7 > _2 3 > > I had categorized Antibase in my mind as useful mainly for converting > between different > > number bases. I can see I need to revisit #: to understand it better. Even > with the above > > example, I don't think I would have discovered that a left argument of 0 1 > to #: could also > > be used to get the whole and fractional parts of any number. > > It would be nice to add another example to the NuVoc Antibase page, to show > how one > > can use #: to get the whole & fractional part of ANY floating point or > rational fraction: > > 0 1 #: 11%3 > > 3 0.666667 > > 0 1 #: 11r3 > > 3 2r3 > > 0 1#: 13r5 136r44 38r13 > > 2 3r5 > > 3 1r11 > > 2 12r13 > > Another surprise was how to use #: to find the odd numbers in an array: > > 4. Detect an odd number > > isOdd=: 2 & #: > isOdd 21 > 1 > isOdd 21 10 31 7 > 1 0 1 1 > > > > Skip Cave > Cave Consulting LLC > > > On Fri, Jul 6, 2018 at 10:17 AM Don Guinn <[email protected]> wrote: > > > 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 > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
