Perl one-liner: approximate pi via Monte Carlo method

http://programmingpraxis.com/2009/10/09/calculating-pi/

>perl -e"print 4/(map{$n+=rand()**2+rand()**2<1}1..pop)*$n" 5000
3.1336

59 characters, plus arguments.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s