Skip to content

Instantly share code, notes, and snippets.

@wiennat
Created February 11, 2014 15:12
Show Gist options
  • Select an option

  • Save wiennat/8936671 to your computer and use it in GitHub Desktop.

Select an option

Save wiennat/8936671 to your computer and use it in GitHub Desktop.
if (A xor B) xor (A xor C) === (B xor C)?
A = '00001111'
B = '00110011'
C = '01010101'
def to_bool(s):
return map(lambda c: True if c == '1' else False, s)
def xorTuple(el):
return el[0] != el[1]
def main():
bA = to_bool(A)
bB = to_bool(B)
bC = to_bool(C)
bAB = zip(bA, bB)
bAC = zip(bA, bC)
bBC = zip(bB, bC)
AxB = map(xorTuple, bAB)
AxC = map(xorTuple, bAC)
BxC = map(xorTuple, bBC)
bABAC = zip(AxB, AxC)
AxBxAxC = map(xorTuple, bABAC)
print all(map(lambda x: x[0] == x[1], zip(BxC, AxBxAxC)))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment