Skip to content

Instantly share code, notes, and snippets.

@DenisGorbachev
Created November 25, 2014 16:38
Show Gist options
  • Save DenisGorbachev/329a68914426a13c9909 to your computer and use it in GitHub Desktop.
Save DenisGorbachev/329a68914426a13c9909 to your computer and use it in GitHub Desktop.
var newZombieCountsByNode = []
for(var nodeIdx = 0; nodeIdx < zombieCountsByNode.length; nodeIdx++) {
var incomingZombies = neighborsByNode[nodeIdx].map(function(neighbor) { return zombieCountsByNode[neighbor] / neighborsByNode[neighbor].length })
newZombieCountsByNode[nodeIdx] = incomingZombies.reduce(function(a,b) {return a + b})
}
var isStabilised = true
for(var nodeIdx = 0; nodeIdx < zombieCountsByNode.length; nodeIdx++) {
if (Math.abs(zombieCountsByNode[nodeIdx] - newZombieCountsByNode[nodeIdx]) > 0.10) {
isStabilised = false
break;
}
}
if (isStabilised) {
newZombieCountsByNode.sort(function(a,b) { return b - a; })
console.log(newZombieCountsByNode.slice(0, 5).map(function(x) { return Math.round(x) }).join(" "))
} else {
runSimulation(neighborsByNode, newZombieCountsByNode)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment