home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / rbemx144.zip / ruby-1.4.4 / sample / pi.rb < prev    next >
Text File  |  1998-01-16  |  326b  |  19 lines

  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
  19.