I always love implementing this (++ if you can tell where the algorithm comes from!)
This version will run (incessantly) as a one-liner as well. -zeno

Update: As MrNobo1024 has answered correctly, this algorithm was discovered by Gregory and Leibniz.

Replies are listed 'Best First'.
Re: one-liner pi
by japhy (Canon) on Feb 15, 2001 at 00:43 UTC
      Hi japhy,
      Correct! I'm still looking for a little something more, though (I did ++ you). This algorithm historically is attributed to someone. Do you know who that someone is? (Hint: He's dead)
        Gregory and Leibniz both discovered that formula.
Re: one-liner pi
by life_monger (Hermit) on Feb 17, 2001 at 00:29 UTC


    I think I preserved the "spirit" of the algorithm :-)

    #!/usr/bin/perl -w use strict; {(redo)while(printf"%.16f\n",$,+=((-1/++$_/(($a||=1)*=($_-$_++)*-1)))* +4)}

Re: one-liner pi
by MrNobo1024 (Hermit) on Feb 15, 2001 at 03:24 UTC
    You should do a $|++ before the program starts, or it won't display anything until you exit :(
      Hi MrNobo1024,

      It didn't happen that way for me... I thought that print did line buffering if it was printing to the terminal, and block buffering when printing to a filehandle.

      However... it nicely obfuscates the code a little more if I do put it in! So I did. Thanks for the tip! ;)