You are viewing a single comment's thread. Return to all comments →
Typescript
function counterGame(n: number): string { if (n === 1) return 'Richard'; let counter = 0; while (n > 1) { const power = Math.log(n) / Math.log(2); if (Number.isInteger(power)) { n = n / 2; } else { n = n - Math.pow(2, Math.floor(power)); } counter++; } return counter % 2 === 0 ? 'Richard' : 'Louise'; }
Seems like cookies are disabled on this browser, please enable them to open this website
Counter game
You are viewing a single comment's thread. Return to all comments →
Typescript