Re: swapping two numbers

Samy Kamkar <[email protected]> Fri, 23 Jun 2006 17:40:45 -0700
Newsgroups gmane.comp.lang.perl.fun
Message-ID <[email protected]>
Although x could overflow in this case, where it wouldn't with an xor, 
right?

Leonid Grinberg wrote:
>> not in-place cause it's 3 lines, but does not use an external temporay
>> value, and should be language-independent:
>>   x = x + y
>>   y = x - y
>>   x = x - y
>> (IIRC my high school BASIC teacher taught us that)
>
> Yeah, that works. Who said that it can't be 3 lines.