Swapping values of two variables

2009-01-29 Thread Eric Kang
In python, I set:

x=1
y=3

z = x
x = y
y = z


This gave me 3 1, which are the values of x and y swapped.
The following would have given me the same result:
x, y = y, x



But could the swapping be done using less extra memory than this? What is the 
minimum amount of extra memory required to exchange two 32-bit quantities? What 
would be the pseudocode that achieves this minimum?
--
http://mail.python.org/mailman/listinfo/python-list


Adding a positive number and a negative number

2009-01-30 Thread Eric Kang
In two’s complement representation, can adding one positive and one negative 
give you overflow?
--
http://mail.python.org/mailman/listinfo/python-list