in reply to Golf -- compute PI

Here's a few more methods of achieving pi:

# 39 Characters

Now, I know Ovid said no Trig functions, but I couldn't resist. Perhaps we could consider the next two examples mulligans :-)

# 45 Characters
use Math::Trig;die 16*atan(1/5)-4*atan(1/239)

# 21 Characters
use Math::Trig;die pi


Update: Taking some of PrakashK's suggestions, shaved off a few more characters. Thanks PrakashK! :-)

Replies are listed 'Best First'.
Re: Re: Golf -- compute PI
by PrakashK (Pilgrim) on Apr 16, 2002 at 04:34 UTC
    # 23 Characters
    use Math::Trig;warn pi;
    Why warn, when you can die saving one more character?
    # 22 Characters use Math::Trig;die pi;
    And, you can shave one more character, if you don't care for that pesky semi-colon at the end.

    Oh, never mind. We are not supposed to use trig functions.


      You can get the same result with 20 chars:
      die 3.14159265358979
      I found this trick in Logique, informatique et paradoxes, publisher Belin (Pour la Science), page 67, it was about the shorter program to get (not compute) pi with n digits.
(MeowChow) Re2: Golf -- compute PI
by MeowChow (Vicar) on Apr 16, 2002 at 06:23 UTC
    17 chars, if you're using trig:
    print 4*atan2 1,1
                   s aamecha.s a..a\u$&owag.print