1 #! /usr/local/bin/python
3 # Print digits of pi forever.
5 # The algorithm, using Python's 'long' integers ("bignums"), works
6 # with continued fractions, and was conceived by Lambert Meertens.
8 # See also the ABC Programmer's Handbook, by Geurts, Meertens & Pemberton,
9 # published by Prentice-Hall (UK) Ltd., 1990.
14 k
, a
, b
, a1
, b1
= 2L, 4L, 1L, 12L, 4L
17 p
, q
, k
= k
*k
, 2L*k
+1L, k
+1L
18 a
, b
, a1
, b1
= a1
, b1
, p
*a
+q
*a1
, p
*b
+q
*b1
23 a
, a1
= 10L*(a
%b
), 10L*(a1
%b1
)
27 # Use write() to avoid spaces between the digits
28 # Use int(d) to avoid a trailing L after each digit
29 sys
.stdout
.write(`
int(d
)`
)
30 # Flush so the output is seen immediately