Skip to main content
added 410 characters in body
Source Link
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.

They:

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

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.

Source Link
JMP
  • 35.7k
  • 7
  • 79
  • 152

They:

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