You are viewing a single comment's thread. Return to all comments →
Ok, the solution seems to be difficult but is reachable with few lines of code.
By the way you can find a better understanding of this problem in wiki: https://en.wikipedia.org/wiki/Nim
function chocolateInBox(arr: number[]): number { var nimsum = 0; var winner = 0; for(let box of arr){ nimsum ^= box}; for(let box of arr){ winner += ((box^nimsum) < box)?1:0;}; return winner; }
Seems like cookies are disabled on this browser, please enable them to open this website
Chocolate in Box
You are viewing a single comment's thread. Return to all comments →
Ok, the solution seems to be difficult but is reachable with few lines of code.
By the way you can find a better understanding of this problem in wiki: https://en.wikipedia.org/wiki/Nim