Skip to content

Instantly share code, notes, and snippets.

@duanebester
Created October 22, 2020 01:32
Show Gist options
  • Save duanebester/9ee93400ce988379640f1ece04d6fbe9 to your computer and use it in GitHub Desktop.
Save duanebester/9ee93400ce988379640f1ece04d6fbe9 to your computer and use it in GitHub Desktop.
Python Workers Checksum Challenge
# Faster XOR
def getXor(a, b):
return [b, 1, b + 1, 0][b % 4] ^ [(a-1), 1, (a-1) + 1, 0][(a-1) % 4]
def solution(start, length):
l = length
cs = 0
while l > 0:
cs ^= getXor(start, start + l - 1)
start = start + length
l = l - 1
return cs
print solution(0, 3) # 2
print solution(17, 4) # 14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment