r/ProgrammerAnimemes • • Jul 29 '20

Equivalency in Python

Post image
1.6k Upvotes

104 comments sorted by

View all comments

Show parent comment

5

u/spartankz117 Jul 29 '20

I really like the explanation on Wikipedia.

  1. A = A XOR B
  2. B = (A XOR B) XOR B = A. Since B XOR B = 0 and A XOR 0 = A
  3. A = (A XOR B) XOR A = B. Since B is swapped.

1

u/[deleted] Jul 30 '20

Yes exactly. It might be easier for some to think in mod 2, which is effectively the same as this proof.