Time for an 2014 update…

This commit is contained in:
Ingy döt Net 2014-01-17 05:32:22 +00:00
parent 372c577f83
commit 09687c4926
2520 changed files with 34227 additions and 7318 deletions

View file

@ -1,8 +1,8 @@
# --- with command line argument "throws" ---
BEGIN{ th=ARGV[1];
for(i=0; i<th; i++) cin += (rand()**2 + rand()**2) < 1 ;
printf("Pi = %8.5f\n",4*cin/th);
for(i=0; i<th; i++) cin += (rand()^2 + rand()^2) < 1
printf("Pi = %8.5f\n",4*cin/th)
}
usage: awk -f pi 2300

View file

@ -0,0 +1,7 @@
function montepi(n)
s = 0
for i = 1:n
s += rand()^2 + rand()^2 < 1
end
return 4*s/n
end