Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

one-liner pi

by zeno (Friar)
on Feb 15, 2001 at 00:34 UTC ( #58445=obfuscated: print w/ replies, xml ) Need Help??

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.

Comment on one-liner pi
Download Code
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! ;)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: obfuscated [id://58445]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2015-11-25 11:59 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (674 votes), past polls