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,4 @@
fcn mean(ns) { ns.sum(0.0)/ns.len() }
fcn stdDev(ns){
m:=mean(ns); (ns.reduce('wrap(p,n){ x:=(n-m); p+x*x },0.0)/ns.len()).sqrt()
}

View file

@ -0,0 +1,9 @@
reg ns;
foreach n in (T(100,1000,10000)){
ns=(0).pump(n,List,(0.0).random.fp(1.0));
println("N:%,6d mean:%.5f std dev:%.5f".fmt(n,mean(ns),stdDev(ns)));
}
foreach r in ([0.0 .. 0.9, 0.1]){ // using the last data set (10000 randoms)
n:=ns.filter('wrap(x){ r<=x<(r+0.1) }).len();
println("%.2f..%.2f:%4d%s".fmt(r,r+0.1,n,"*"*(n/20)));
}

View file

@ -0,0 +1,13 @@
var pipe=Thread.Pipe(); // used to connect the two threads
fcn{ while(1){ pipe.write((0.0).random(1.0)) } }.launch(); // generator
fcn{ // consumer/calculator
N:=0; M:=SD:=sum:=ssum:=0.0;
while(1){
x:=pipe.read(); N+=1; sum+=x; ssum+=x*x;
M=sum/N; SD=(ssum/N - M*M).sqrt();
if(0==N%100000)
println("N:%,10d mean:%.5f std dev:%.5f".fmt(N,M,SD));
}
}.launch();
Atomic.sleep(60*60); // wait because exiting the VM kills the threads