|
|
Other versions: 1.0
pidigits
routine gen_x()
{ for( k = 1 : ) yield( k+0L, 4L*k + 2L, 0L, 2L*k + 1L ); return (0L,0L,0L,0L); } routine compose( (aq =0L, ar =0L, as_ =0L, at =0L), (bq =0L, br =0L, bs =0L, bt =0L) ) { return ( aq*bq, aq*br + ar*bt, as_*bq + at*bs, as_*br + at*bt ); } routine extract( (q=0L,r=0L,s=0L,t=0L), j=0 ) { return (int)( (q*j + r) / (s*j + t) ); } routine pi_digits() { z = (1L, 0L, 0L, 1L); x = @gen_x(); while(1){ while( ( y=extract(z,3) ) != extract(z, 4) ) z = compose(z, x() ); z = compose((10L, -10L*y, 0L, 1L), z); yield( y ); } return 0; } routine main( n = 200 ) { const width = 10; digits = @pi_digits(); for(i = 0 : width : n-1 ){ s = string( width )->{ (string)digits() }; stdio.printf( '%s\t:%d\n', s.sum(), i+width ); } }
view count 483 times
created at 2009-02-20, 16:31 GMT modified at 2009-09-17, 02:15 GMT |
fu: Many thanks (Jul.04,04:29) klabim: fixed Hi, great, now my test works now :- ). (Jun.30,17:51) Nightwalker: Few suggestions (Jul.03,14:37) |