Hi people, my first perlmonks post, and my first attempt at a piece of obfuscated code. Be gentle.

This calculates pi .... slowly. It's actually an approximation that becomes more accurate over time. I'm not a mathematician - can you tell? :-) I can't remember where I read this algorithm, but it rapidly becomes rather slow to get new digits out - very brute force.

perl -e '$a=$b=1;while(){$b=$b-1/($a+=2)+1/($a+=2);print$b*4 ."\n"unless$a%566661}'

perls handling of floating point numbers probably introduces errors fairly quickly. My computer is not fast enough to get an accurate enough pi to test this :-)

Would welcome any comments - a more efficient (in terms of bytes of code) way of printing out every X'th approximation of pi would be good - I don't think much of how it is now.

Replies are listed 'Best First'.
Re: Slow cookin' pi
by Prince99 (Scribe) on Jul 14, 2001 at 01:04 UTC
    I can't give you much direction as far as what to do, but you weren't kidding about being slow. The following output took approx. 3 minutes before I decided to break out of it:
    3.14159618303062 3.14159335947899 3.14159304575042 3.14159292508549 3.14159286120424 3.1415928216587 3.14159279476759 3.14159277529483 3.14159276054275 3.14159274898025

    I give you high marks on coming up with the one-liner obfuscated, but who has that time.
    Prince99

    Too Much is never enough...