-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathowen.js
41 lines (34 loc) · 990 Bytes
/
owen.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const _ = require("lodash");
let people = [];
const networkSize = 10;
const infectionRate = 0.1;
const populationSize = 40000
const pandemicPeriod = 10;
const startingPopulation = 10;
for(let i = 0; i < populationSize; i++) {
const person = {};
person.id = i;
person.infected = false;
people.push(person);
}
let infected = _.sampleSize(people, startingPopulation);
infected.forEach(p => p.infected = true);
const runInfectionDay = () => {
let infectors = people.slice(0, people.length);
while(infectors.length) {
let me = infectors.pop();
let friends = _.sampleSize(infectors, networkSize);
friends.forEach(friend => {
if(friend.infected && Math.random() <= infectionRate) {
me.infected = true;
}
if(me.infected && Math.random() <= infectionRate) {
friend.infected = true;
}
});
}
}
for(let days = 0; days < pandemicPeriod; days++) {
runInfectionDay();
console.log(people.filter(p => p.infected).length);
}