OneFoo
#!/usr/bin/perl # Two Monte Carlo approximations of 1. Slow! use strict; use warnings; my $in = 0; my $count = @ARGV ? shift : 1000; rand () + rand () < 1 && $in ++ for 1 .. $count; printf "One equals %f\n", 2 * $in / $count; $in = 0; rand () < .5 && rand () < .5 && $in ++ for 1 .. $count; printf "Or maybe %f\n", 4 * $in / $count;
In reply to Re: Monte Carlo approximation of PI
by YuckFoo
in thread Monte Carlo approximation of PI
by Abigail-II
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |