|
|
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 1146 times
created at 2009-02-20, 16:31 GMT modified at 2009-09-17, 02:15 GMT |
fu: ... I forgot to say something about the plan for the whole new year in my previous reply. Well, besides w ... (Jan.19,01:40) fu: ... Happy new dragon year (which will start from this sunday)! Actually, it was a busy month (I wish th ... (Jan.18,22:46) ybabel: What's the plan for the new year ? Hello 'vry budy :- ) happy new year (when is the new year for you Fu ?) I saw you come back and comm ... (Jan.18,18:59) |