Skip to content

Instantly share code, notes, and snippets.

@chonghorizons
Created April 14, 2020 04:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chonghorizons/0f78aa3209da430c26bcbbd2b2790c64 to your computer and use it in GitHub Desktop.
Save chonghorizons/0f78aa3209da430c26bcbbd2b2790c64 to your computer and use it in GitHub Desktop.
var probability=0.01 // 1%
var initialsize=500 //
var waves=[50,5,2,1]
// var probability=0.10 // 10%
// var initialsize=50 //
// var waves=[2,1]
// See this medium article on batch testing for the coronavirus:
// https://medium.com/@coronavirusnotalone/the-secret-way-to-reopen-schools-with-batch-testing-for-coronavirus-616433cd5ba4
// https://medium.com/@coronavirusnotalone/a-secret-simple-way-to-detect-the-coronavirus-without-a-test-for-everyone-9e06afb2823a
function processWaves(startvalue,endvalue,waveindex) {
console.log("processing " + startvalue + "start " + endvalue + "end " + waveindex + "waveindex");
let localTestCount=0;
// debugger;
if (startvalue==endvalue) {
// the batch size is 1
// console.log("size1");
return 1;
}
//check for any true
var someTrue= arrayOfInfection.slice(startvalue,endvalue+1).some((x)=> x==true);
if (someTrue) {
localTestCount++
// console.log("some true")
// debugger;
var waveSize=waves[waveindex];
var currentvalue=startvalue;
while( currentvalue<=endvalue ) {
localTestCount=localTestCount+processWaves(currentvalue,Math.min(currentvalue+waveSize-1),waveindex+1);
currentvalue=currentvalue+waveSize;
}
return localTestCount;
} else {
// console.log("all negative")
return 1; // localTestCount
}
}
var arrayOfResults=[];
var repetitions=500;
for (let i=0; i<repetitions; i++) {
console.log("iteration " + i );
var arrayOfRandom = Array.from({length: initialsize}, () => Math.random());
var arrayOfInfection = arrayOfRandom.map( (x) => (x<probability) );
var MyResult= processWaves(0,initialsize-1,0);
console.log("MAIN RESULT");
console.log(MyResult);
arrayOfResults.push(MyResult);
}
console.log("Average over repititions " + repetitions);
var Average= arrayOfResults.reduce((a,b) => a + b, 0) / arrayOfResults.length
console.log(Average)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment