Other versions: 1.0

Change picture:

Choose file:

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  );
       }
       return0;
}
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 516 times
created at 2009-02-20, 16:31 GMT
modified at 2009-09-17, 02:15 GMT

123 4
56789 10 11
121314151617 18
192021222324 25
2627282930

fu: Fixed and updated There was a minor bug in storing returned value in the DaoVmProcess structure. Now it is fixed and up ... (Sep.07,23:43)

klabim: ... Ok, I found it. It can be so easy by reading the documentation :- ). I have overseen the keyword glob ... (Aug.21,18:09)

klabim: returning a string from function to c++ code! Hi, I run in some trouble while calling a dao function from the c++ code. The dao function should re ... (Sep.07,19:44)

klabim: sharing vars between scripts Hi, how can I share a variable between 2 scripts in an embedded environment? For example: script 1: ... (Aug.21,17:55)

This site is powered by Dao
Copyright (C) 2009,2010, daovm.net.
Webmaster: admin@daovm.net