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

Re: Golf -- compute PI

by pepik_knize (Scribe)
on Apr 16, 2002 at 15:54 UTC ( #159541=note: print w/replies, xml ) Need Help??

in reply to Golf -- compute PI

Here's one using Archimedes's method that comes in at 67:


As a side note, I had $_ instead of $p inside the curlies, but using just print outside didn't work, and I don't know why.


Replies are listed 'Best First'.
Re: Re: Golf -- compute PI
by Ovid (Cardinal) on Apr 16, 2002 at 16:54 UTC

    Using $_ instead of $p is a nice try to save two strokes, but it fails because for(1..9){..} aliases elements of the range to $_, which overwrites your later use of $p. Good job, though.


    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Re: Re: Golf -- compute PI
by blakem (Monsignor) on Apr 17, 2002 at 06:41 UTC
    You could use $\ instead, which will trim the two chars at the expense of an 'uninitialized' warning....
    Infact, if you rearrange things and toss in a little obfu, you can trim a few more chars. It even has the side-effect of making it strict compliant:
    $@=3;$;=1;$@*=2,$;=(2-(4-$;**2)**.5)**.5,$\=$@*$;for 1..9;print


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2022-08-19 17:53 GMT
Find Nodes?
    Voting Booth?

    No recent polls found