On 16 January 2013 17:05, Devon McCormick <[email protected]> wrote: > ............ > NB. Programmatically: > > 13 : '%/x: (y*-/x),-/x' > [: %/ [: x: (] * [: -/ [) , [: -/ [ > 1000 10 ([: %/ [: x: (] * [: -/ [) , [: -/ [) 0.624242424 NB. Not > enough digits for y? > 2574998969r4124998350 > 1000 10 ([: %/ [: x: (] * [: -/ [) , [: -/ [) 0.6242424242424 > 103r165 > ............
To do the conversion programmatically, we only need to know two things: the repetend, and the part that precedes it. Each of them can be empty, so let them be strings. s2n =. 0:`".@.(0&<@#) pt =. [:x:10&^@# rd2x =. (s2n@[+(s2n%<:@pt)@])%pt@[ '' rd2x '3' NB. 0.(3) 1r3 '' rd2x '1' NB. 0.(1) 1r9 '' rd2x '9' NB. 0.(9) 1 '00' rd2x '9' NB. 0.00(9) 1r100 '6' rd2x '24' NB. 0.6(24) 103r165 '635' rd2x '24' NB. 0.635(24) 20963r33000 '12' rd2x '358' NB. 0.12(358) 6173r49950 '15' rd2x '' NB. 0.15 (non-periodic) 3r20 '23' rd2x '' NB. 0.23 (non-periodic) 23r100 ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
