Last active
December 27, 2015 23:39
-
-
Save eclairevoyant/7407575 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vals = [0, 1, 3, 0] | |
def xor(n): | |
return((n - (n & 3)) * (1 ^ (n & 1)) + vals[n & 3]) | |
def getXor(l, r): | |
return(xor(l - 1) ^ xor(r)) | |
if __name__ == "__main__": | |
print(getXor(3, 10)) # 8 | |
print(getXor(5, 5)) # 5 | |
print(getXor(666, 1337)) # 0 | |
print(getXor(1234567, 89101112)) # 89998783 | |
print(getXor(1, 4*10**9)) # 4000000000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment