Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Golf -- compute PI

by jsprat (Curate)
on Apr 16, 2002 at 01:55 UTC ( [id://159388]=note: print w/replies, xml ) Need Help??


in reply to Golf -- compute PI

How about this (72 strokes - about par for the course ;-) for($i;$i<100000;$i+=2){$_.="+4/(($i*2)+1)-4/((($i+1)*2)+1)"};print eval

I'm assuming the algorithm can't be changed.
I just got rid of the neat closure and built it all in the loop. It's got the same five digits of accuracy. The same 72 strokes can have up to a whopping 6 digits of accuracy if you change the 100_000 to 999_999!

jsprat

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-25 23:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found