Skip to main content
2 of 2
added 410 characters in body
JMP
  • 35.7k
  • 7
  • 79
  • 152

They:

Exchange their treasures one coin/gem at a time - this way, any losses are minimized.

Alternatively:

We wish to swap the values of P and M without either ever having more than the other (and thus running off with all the loot!). This is IMPOSSIBLE - the only swap routines using only two variables invariably create the scenario with one variable greater than the other. For example, the XOR swap algorithm.

JMP
  • 35.7k
  • 7
  • 79
  • 152