Re: swapping two numbers

2006-06-25 Thread Yitzchak Scott-Thoennes
On Sun, Jun 25, 2006 at 12:31:19AM -0700, Larry Rosler wrote: From: Philippe BooK Bruhat Sent: Saturday, June 24, 2006 04:10 To: fwp@perl.org Subject: Re: swapping two numbers Le vendredi 23 juin 2006 ? 17:40, Samy Kamkar ?crivait: Although x could overflow in this case, where

Re: swapping two numbers

2006-06-24 Thread Samy Kamkar
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

Re: swapping two numbers

2006-06-24 Thread Chris Dolan
On Jun 23, 2006, at 5:01 PM, David Westbrook wrote: Michael R. Wolf 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) This works:

Re: swapping two numbers

2006-06-24 Thread Philippe BooK Bruhat
Le vendredi 23 juin 2006 à 17:40, Samy Kamkar écrivait: Although x could overflow in this case, where it wouldn't with an xor, right? I've quickly tried to overflow it, but I didn't manage to break it. It looks like even if you overflow x with the first addition, you cross the border in the

RE: SPUG: swapping two numbers

2006-06-23 Thread DeRykus, Charles E
M I was digging through some old code and came across a proof that I had done M that you can swap two numbers in place (i.e. without using an external M temporary value). M Of course, in Perl, we can just do this: M ($x, $y) = ($y, $x) M But I was challenged (at a GSLUG meeting) to do it in