As others have said, 2 x: y does it.
The problem is an interesting puzzle
if you didn't have 2 x: y.  Spoiler below.

















   denominator=: %@(1&+.)
   numerator  =: * denominator

   ] y=: %/ x: _1e9 + ?. 2 $ 2e9
905093854r670464245
   denominator y
670464245
   numerator y
905093854



----- Original Message -----
From: Brian Schott <[email protected]>
Date: Tuesday, March 3, 2009 20:01
Subject: [Jprogramming] deconstructing rationals
To: [email protected]

>       How do you get the numerator and denominator of a
> rational fraction? For example the (numerator,denominator)
> of 4r6 is 2 3; how do you get the 2 3 from 4r6? I know this
> must have been covered before, but I cannot think how to
> search for it.
> 
>       My current best effort is the verb ratio.
>    ratio =: 2{.!.1 (i.&'r' ( {./  , ' ' , ] }.~ 
> #...@] <. >:@[) ])&.":
>    ratio 4r6
> 2 3
>    ratio 4
> 4
>    $ratio 4
> 
>    $ratio 4r6
> 2
>    #ratio 4
> 1
>    #ratio 4r6
> 2
>    ratio"0 ]4r6 6r4 79
>  2 3
>  3 2
> 79 1
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to