On 2009-01-31, Aahz wrote:
>>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?
>
> This looks like a homework problem to me
It l
In article ,
Eric Kang wrote:
>
>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
> Grant Edwards wrote:
> > On 2009-01-30, MRAB wrote:
> >
> >>> What is the minimum amount of extra memory required to exchange two
> >>> 32-bit quantities? What would be the pseudocode that achieves this
> >>> minimum?
> >> x ^= y
> >> y ^= x
> >> x ^= y
> >>
> >> This is really only of use when
Steven D'Aprano schrieb:
> Ints in Python are *objects*, not 32-bit quantities. An int is 12 bytes
> (96 bits) in size; a long will use as much memory as needed. If your
> application needs to optimize a swap of two ints, then Python is probably
> going to be much too memory-intensive for you.
Grant Edwards wrote:
> On 2009-01-30, MRAB wrote:
>
>>> What is the minimum amount of extra memory required to exchange two
>>> 32-bit quantities? What would be the pseudocode that achieves this
>>> minimum?
>> x ^= y
>> y ^= x
>> x ^= y
>>
>> This is really only of use when working in assembly l
On Thu, 29 Jan 2009 21:23:48 -0800, Kottiyath wrote:
> Is it possible to swap two floats without a variable?
In Python? Sure.
f = 1.23
g = 2.87
f, g = g, f
This idiom is independent of the types of the objects:
x = "hello world"
y = [1, 2.0, None, "xyz", {}]
x, y = y, x
In other languages?
On Jan 30, 3:31 am, Steven D'Aprano
wrote:
> On Thu, 29 Jan 2009 17:50:04 -0800, tony.clarke5 wrote:
> > On Jan 30, 12:29 am, Eric Kang wrote:
> >> 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
> >> f
On 2009-01-30, MRAB wrote:
>> What is the minimum amount of extra memory required to exchange two
>> 32-bit quantities? What would be the pseudocode that achieves this
>> minimum?
>
> x ^= y
> y ^= x
> x ^= y
>
> This is really only of use when working in assembly language.
And rarely then. ;)
On Jan 30, 8:31 am, Steven D'Aprano
wrote:
> On Thu, 29 Jan 2009 17:50:04 -0800, tony.clarke5 wrote:
> > On Jan 30, 12:29 am, Eric Kang wrote:
> >> 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
> >> f
On Thu, 29 Jan 2009 17:50:04 -0800, tony.clarke5 wrote:
> On Jan 30, 12:29 am, Eric Kang wrote:
>> 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
>>
On Thu, 29 Jan 2009 16:29:11 -0800, Eric Kang wrote:
> 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
Yes.
> But could the swapping be done using less
On Jan 30, 12:29 am, Eric Kang wrote:
> 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?
Eric Kang wrote:
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
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 exch
14 matches
Mail list logo