You are viewing a single comment's thread. Return to all comments →
JS version of jsonmartin's python implementation given here
function permutationGame(arr) { const memo = {} const inc = arr => arr.every((v, i, a) => i === a.length - 1 || a[i] < a[i + 1] ) function rec(arr) { let key = arr.join('|') if (memo[key]) return memo[key] if (inc(arr)) return memo[key] = true for (let idx = 0; idx < arr.length; idx++) if (rec(arr.slice(0, idx).concat(arr.slice(idx + 1)))) return memo[key] = false return memo[key] = true } return rec(arr) ? 'Bob' : 'Alice' }
Seems like cookies are disabled on this browser, please enable them to open this website
Permutation game
You are viewing a single comment's thread. Return to all comments →
JS version of jsonmartin's python implementation given here