+++ /dev/null
-#! /usr/bin/env python\r
-\r
-# Print digits of pi forever.\r
-#\r
-# The algorithm, using Python's 'long' integers ("bignums"), works\r
-# with continued fractions, and was conceived by Lambert Meertens.\r
-#\r
-# See also the ABC Programmer's Handbook, by Geurts, Meertens & Pemberton,\r
-# published by Prentice-Hall (UK) Ltd., 1990.\r
-\r
-import sys\r
-\r
-def main():\r
- k, a, b, a1, b1 = 2, 4, 1, 12, 4\r
- while True:\r
- # Next approximation\r
- p, q, k = k*k, 2*k+1, k+1\r
- a, b, a1, b1 = a1, b1, p*a+q*a1, p*b+q*b1\r
- # Print common digits\r
- d, d1 = a//b, a1//b1\r
- while d == d1:\r
- output(d)\r
- a, a1 = 10*(a%b), 10*(a1%b1)\r
- d, d1 = a//b, a1//b1\r
-\r
-def output(d):\r
- # Use write() to avoid spaces between the digits\r
- sys.stdout.write(str(d))\r
- # Flush so the output is seen immediately\r
- sys.stdout.flush()\r
-\r
-if __name__ == "__main__":\r
- main()\r