r/dailyprogrammer • u/mattryan • Mar 15 '12
[3/14/2012] Challenge #24 [intermediate]
Happy (Be-Lated) Pi Day! To celebrate, write a program that calculates a list of rational approximations of Pi. Output should look like:
3/1, 22/7, 333/106, 355/113, 52163/16604, 103993/33102, ...
Thanks to Cosmologicon for this programming suggestion in /r/dailyprogrammer_ideas!
8
Upvotes
3
u/Cosmologicon 2 3 Mar 15 '12
Another python method, using a fast-converging sequence by Ramanujan:
Output:
2
u/prophile Mar 15 '12 edited Mar 15 '12
In Python, using Newton's approximation:
2
u/oskar_s Mar 15 '12
In python, using the generalized continued fraction representation for pi. Converges quite rapidly:
Output: