We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
The same modulus 8 solution in JavaScript/Node.js:
function getXor(x) {
let n = x % 8;
if (n === 0 || n === 1) return x;
if (n === 2 || n === 3) return 2;
if (n === 4 || n === 5) return x + 2;
return 0;
}
Xor-sequence
You are viewing a single comment's thread. Return to all comments →
The same modulus 8 solution in JavaScript/Node.js:
function getXor(x) { let n = x % 8; if (n === 0 || n === 1) return x; if (n === 2 || n === 3) return 2; if (n === 4 || n === 5) return x + 2; return 0; }
function xorSequence(l, r) { return BigInt(getXor(r)) ^ BigInt(getXor(l - 1)); }