Skip to content

Instantly share code, notes, and snippets.

@chrisisbeef
Created September 30, 2016 16:27
Show Gist options
  • Save chrisisbeef/787fb49a640627b09c8282037d918995 to your computer and use it in GitHub Desktop.
Save chrisisbeef/787fb49a640627b09c8282037d918995 to your computer and use it in GitHub Desktop.
How to explain the birds and bees to a young programmer
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