September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -0,0 +1,33 @@
const N=20;
(" N average analytical (error)").println();
("=== ========= ============ =========").println();
foreach n in ([1..N]){
a := avg(n);
b := ana(n);
"%3d %9.4f %12.4f (%6.2f%%)".fmt(
n, a, b, ((a-b)/b*100)).println();
}
fcn f(n){ (0).random(n) }
fcn avg(n){
tests := 0d10_000;
sum := 0;
do(tests){
v:=(0).pump(n,List,T(Void,False)).copy();
while(1){
z := f(n);
if(v[z]) break;
v[z] = True;
sum += 1;
}
}
return(sum.toFloat() / tests);
}
fcn fact(n) { (1).reduce(n,fcn(N,n){N*n},1.0) } //-->Float
fcn ana(n){
n=n.toFloat();
(1).reduce(n,'wrap(sum,i){ sum+fact(n)/n.pow(i)/fact(n-i) },0.0);
}