Skip to content

Instantly share code, notes, and snippets.

@one19
Created November 15, 2020 07:23
Show Gist options
  • Save one19/b1b711b4eeffcfb9bcf27356df2e21d2 to your computer and use it in GitHub Desktop.
Save one19/b1b711b4eeffcfb9bcf27356df2e21d2 to your computer and use it in GitHub Desktop.
Jeopardy! 538 brain teaser
const row200 = [200, 200, 200, 200, 200, 200];
const row400 = [400, 400, 400, 400, 400, 400];
const row600 = [600, 600, 600, 600, 600, 600];
const row800 = [800, 800, 800, 800, 800, 800];
const row1000 = [1000, 1000, 1000, 1000, 1000, 1000];
const lowest = [row200, row400, row600, row800, row1000].flat();
const highest = [row1000, row800, row600, row400, row200].flat();
const sum = things => things.reduce((summa, item) => summa + item, 0);
const average = things => sum(things) / things.length;
const getAllScores = configuration =>
configuration.map((score, index) => {
const preSum = sum(configuration.slice(0, index));
const doubleScore = preSum < 1000 ? 1000 : preSum;
const remainder = sum(configuration.slice(index + 1, configuration.length));
return preSum + doubleScore + remainder;
});
const low = getAllScores(lowest);
const high = getAllScores(highest);
console.log('lowest average score configuration: ', average(low));
console.log('highest average score configuration: ', average(high));
console.log('average of those two (random average): ', average([average(low), average(high)]));
@one19
Copy link
Author

one19 commented Nov 15, 2020

Although, my assumption that the relationship between the highest edge case and the lowest edge case is linear is just that... an assumption.

If, however, a random distribution of configurations produces a nonlinear relationship, the bonus answer will be inaccurate, but for guesstimates, halfway between edge cases is good enough. Especially when the best and worse case scenarios are so similar.

@one19
Copy link
Author

one19 commented Nov 23, 2020

https://fivethirtyeight.com/features/can-you-pass-the-cranberry-sauce/
awesome! I had it right on the correct submission, any my average fo the averages was less than 20$ off the fully correct solution, the one that would have required 4.1x10^19 runs (or a monte carlo) :D

quite happy with that level of detail. (26166 estimated vs 26150)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment