Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: Golf -- compute PI

by andreychek (Parson)
on Apr 16, 2002 at 04:05 UTC ( #159407=note: print w/replies, xml ) Need Help??

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

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://159407]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2022-10-04 22:22 GMT
Find Nodes?
    Voting Booth?
    My preferred way to holiday/vacation is:

    Results (19 votes). Check out past polls.