Programming quiz

Now ... I found something very interesting I never stumbled upon till now.

(for a reason)

Write a program which swaps the values of 2 integer variables, without using a 3rd varialbe.

In perl of course is super easy :

($a,$b) = ($b, $a);

What are we looking for tough is writing a solution in an inferior language with no superb syntax trickery :)

I'm not gonna post the solution, but will keep an eye on the comments, feel free to be first to solve it.

Marin

3 comments
16.03.2010 Author: Daniel Freeman
The solution I hinted at (exclusive-or, cryptic...encryption), uses the exclusive or operator ^

a = a ^ b;
b = b ^ a;
a = a ^ b;
12.03.2010 Author: Marin
no takers though :)
here 1 solution for vars $a and $b.

$a = $a+$b;
$b = $a-$b;
$a = $a-$b;

there ya go :)

09.03.2010 Author: Daniel Freeman
It will take a clever programmer to crack this one. Someone exclusive or crypic perhaps ;)
 
Add comment:
Name*:
Email*:
Comment*:
Code*:


Please enter the code in the image in the text field.

If you cannot read it, generate new one
Generate new code
 


iPhone art gallery - Digital Crowberries by Kunstdrom