Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,29 @@
|
|||
const X=-1; // the sentinal that marks an untouched cell
|
||||
var C,N,NN,P;
|
||||
fcn createC(n,p){
|
||||
N,P=n,p; NN=N*N;
|
||||
C=NN.pump(List.createLong(NN),0); // vector of ints
|
||||
foreach n in (NN){ C[n]=X*(Float.random(1)<=P) } // X is the sentinal
|
||||
}
|
||||
fcn showCluster{
|
||||
alpha:="-ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz";
|
||||
foreach n in ([0..NN,N]){ C[n,N].pump(String,alpha.get).println() }
|
||||
}
|
||||
fcn countClusters{
|
||||
clusters:=0;
|
||||
foreach n in (NN){
|
||||
if(X!=C[n]) continue;
|
||||
fcn(n,v){
|
||||
if((0<=n<NN) and C[n]==X){
|
||||
C[n]=v;
|
||||
self.fcn(n-N,v); self.fcn(n-1,v); self.fcn(n+1,v); self.fcn(n+N,v);
|
||||
}
|
||||
}(n,clusters+=1);
|
||||
}
|
||||
clusters
|
||||
}
|
||||
fcn tests(N,n,p){
|
||||
k:=0.0;
|
||||
foreach z in (n){ createC(N,p); k+=countClusters().toFloat()/NN; }
|
||||
k/n
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
createC(15,0.5);
|
||||
println("width=%d, p=%.1f, %d clusters:".fmt(N,P,countClusters()));
|
||||
showCluster();
|
||||
|
||||
println("p=0.5, 5 iterations:");
|
||||
w:=4; do(6){ println("%5d %9.6f".fmt(w,tests(w, 5, 0.5))); w*=4; }
|
||||
Loading…
Add table
Add a link
Reference in a new issue