Skip to content

Instantly share code, notes, and snippets.

@dleshem
Last active March 25, 2019 09:52
Show Gist options
  • Save dleshem/98bfb50803a332b5150cd17bfda6a0e9 to your computer and use it in GitHub Desktop.
Save dleshem/98bfb50803a332b5150cd17bfda6a0e9 to your computer and use it in GitHub Desktop.
const past = new Map();
let last = 'LRLRL';
for (let i = 0; i < 1000; ++i) {
const stats = past.get(last) || {L: 0, R: 0};
const choice = (stats.L >= stats.R) ? 'R' : 'L';
console.log(choice);
++stats[choice];
past.set(last, stats);
last = last.substr(-4, 4) + choice;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment