Created
September 30, 2016 16:27
-
-
Save chrisisbeef/787fb49a640627b09c8282037d918995 to your computer and use it in GitHub Desktop.
How to explain the birds and bees to a young programmer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let process = teenage_child; | |
function teenage(process) { | |
while(true) { | |
let processList = this.getProcesses(); | |
for (let potential in processList) { | |
process.greet(potential); | |
if (potential.isWarm()) { | |
try { | |
process.offer(potential); | |
if (!process.isProtected()) { | |
if (process.isSafe() && potential.isSafe()) { | |
let chance = Math.rand(); | |
if (change <= .5) { | |
throw new NoException("Not with an unprotected process! Are you crazy!?"); | |
} else { | |
process.join(potential); | |
} | |
} | |
} else { | |
process.join(potential); | |
} | |
} catch (noException) { | |
continue; | |
} | |
} | |
if (process.isJoined(potential)) { | |
try { | |
let threshold = .5 + (process.getFertility() * potential.getFertility() * potential.joinedCount(process)); | |
let chance = Math.rand(); | |
if (chance <= threshold) { | |
let NINE_MONTHS = 1000 * 60 * 60 * 24 * 30 * 9; | |
potential.schedule(NINE_MONTHS, this.spawn.push(potential.fork())); | |
potential.on("fork", new function(process) { | |
this.notify(process); | |
process.break(); | |
}); | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment