Commit 0b2b440a authored by Guido van Rossum's avatar Guido van Rossum

all Long constants have an L suffix, not l;

added an output() function to move the I/O out of the algorithm
parent 0cc19450
...@@ -11,20 +11,23 @@ ...@@ -11,20 +11,23 @@
import sys import sys
def main(): def main():
k, a, b, a1, b1 = 2l, 4l, 1l, 12l, 4l k, a, b, a1, b1 = 2L, 4L, 1L, 12L, 4L
while 1: while 1:
# Next approximation # Next approximation
p, q, k = k*k, 2l*k+1l, k+1l p, q, k = k*k, 2L*k+1L, k+1L
a, b, a1, b1 = a1, b1, p*a+q*a1, p*b+q*b1 a, b, a1, b1 = a1, b1, p*a+q*a1, p*b+q*b1
# Print common digits # Print common digits
d, d1 = a/b, a1/b1 d, d1 = a/b, a1/b1
#print a, b, a1, b1
while d == d1: while d == d1:
# Use write() to avoid spaces between the digits output(d)
sys.stdout.write(`int(d)`) a, a1 = 10L*(a%b), 10L*(a1%b1)
# Flush so the output is seen immediately
sys.stdout.flush()
a, a1 = 10l*(a%b), 10l*(a1%b1)
d, d1 = a/b, a1/b1 d, d1 = a/b, a1/b1
def output(d):
# Use write() to avoid spaces between the digits
# Use int(d) to avoid a trailing L after each digit
sys.stdout.write(`int(d)`)
# Flush so the output is seen immediately
sys.stdout.flush()
main() main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment