sample/pi.rb


DEFINITIONS

This source file includes following functions.


   1  #!/usr/local/bin/ruby
   2  
   3  k, a, b, a1, b1 = 2, 4, 1, 12, 4
   4  
   5  while TRUE
   6    # Next approximation
   7    p, q, k = k*k, 2*k+1, k+1
   8    a, b, a1, b1 = a1, b1, p*a+q*a1, p*b+q*b1
   9    # Print common digits
  10    d = a / b
  11    d1 = a1 / b1
  12    while d == d1
  13      print d
  14      $stdout.flush
  15      a, a1 = 10*(a%b), 10*(a1%b1)
  16      d, d1 = a/b, a1/b1
  17    end
  18  end