I wrote a little script to calculate pi based on the series (-1)^(n+1) * (1/(2n-1)).
It does the first million iterations, and is fairly accurate, I get: 3.14159165358977
here's the script:
#!/usr/bin/perl -w
$pi = 0;
for($n = 1; $n <= 1000000; $n++){
$pi += (-1)**($n+1) * (1/(2 * $n - 1));
}
$pi *= 4;
print "$pi\n";
I'm sure there are more effecient ways than that, and there are those calcultors on line that can jsut keep spitting out pi to as many places as you like.
Anyone got any good pi computations?
It does the first million iterations, and is fairly accurate, I get: 3.14159165358977
here's the script:
#!/usr/bin/perl -w
$pi = 0;
for($n = 1; $n <= 1000000; $n++){
$pi += (-1)**($n+1) * (1/(2 * $n - 1));
}
$pi *= 4;
print "$pi\n";
I'm sure there are more effecient ways than that, and there are those calcultors on line that can jsut keep spitting out pi to as many places as you like.
Anyone got any good pi computations?
