Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
14
Task/Monte-Carlo-methods/Perl/monte-carlo-methods.pl
Normal file
14
Task/Monte-Carlo-methods/Perl/monte-carlo-methods.pl
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
sub pi {
|
||||
my $nthrows = shift;
|
||||
my $inside = 0;
|
||||
foreach (1 .. $nthrows) {
|
||||
my $x = rand() * 2 - 1;
|
||||
my $y = rand() * 2 - 1;
|
||||
if (sqrt($x*$x + $y*$y) < 1) {
|
||||
$inside++;
|
||||
}
|
||||
}
|
||||
return 4 * $inside / $nthrows;
|
||||
}
|
||||
|
||||
printf "%9d: %07f\n", $_, pi($_) for 10**4, 10**6;
|
||||
Loading…
Add table
Add a link
Reference in a new issue