If you can't figure out how to do this with the simple `XOR' approach, it is because you have a broken implementation or didn't implement the logic correctly, but you seem to have the right idea. If you post what you have, instead of just saying you've tried what you know, I imagine that you'll get pointed in the right direction.I tried to solve it using XOR approach, from where I could not conclude anything fruitful.

Soma