Skip to content

Instantly share code, notes, and snippets.

@bencooper222
Last active Jan 27, 2021
Embed
What would you like to do?
Runs thousands of trials to evaluate whether putting the seat down or up or not changing it is best
https://shared.benc.io/screencaps/2018/09/Oropendula/24704094-46c0-4af6-afdb-56f7747625bc.png
That graph shows the default code's (seen above) results. Lower on the graph means better. This graph indicates that the best approach is to leave the seat where you had it except in the niche case where there is less than 2% biological males using that toilet. My guess is that would only apply to biological males who have undergone a gender change and now use the women's restroom.
const TOTAL_PEOPLE = 20000;
const FREQUENCY = { 1: 6.5, 2: 1 }; // number 1 vs number 2
const doTrials = (percentMale = PERCENT_MALE, setTo = 'same') => {
let isUp = false; // false = down
const strategy = results => {
// penalizing any changes made after you've "gone"
if (setTo !== 'same' && setTo !== isUp) {
results.needChange++;
} else {
results.noChange++;
}
isUp = setTo === 'same' ? isUp : setTo;
};
const results = { needChange: 0, noChange: 0 };
for (let i = 0; i < TOTAL_PEOPLE; i++) {
const isMale = Math.random() < percentMale;
let neededState;
if (isMale) {
neededState =
Math.random() < FREQUENCY[1] / (FREQUENCY[2] + FREQUENCY[1]);
} else {
// female
neededState = false;
}
if (isUp !== neededState) {
// if a change is needed
results.needChange++;
isUp = !isUp;
} else {
results.noChange++;
}
strategy(results);
}
return results.needChange / (results.needChange + results.noChange); //
};
(() => {
let percentMale = 1; // starting percentage
const results = [];
while (percentMale > 0) {
const strategyRecords = {
percentMale,
down: 0,
same: 0,
up: 0,
};
const NUM_TRIES = 6;
for (let i = 0; i < NUM_TRIES; i++) {
strategyRecords.same += doTrials(percentMale); // leaving it wherever you left it
strategyRecords.up += doTrials(percentMale, true); // always leaving it up
strategyRecords.down += doTrials(percentMale, false); // always leaving it down
}
strategyRecords.same /= NUM_TRIES;
strategyRecords.up /= NUM_TRIES;
strategyRecords.down /= NUM_TRIES;
results.push(strategyRecords);
percentMale -= 0.005;
}
results.forEach(trial =>
console.log(
`${trial.percentMale}, ${trial.same}, ${trial.up}, ${trial.down}`,
),
);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment