What is the slowest algorithm you can think of that swaps two variables, x and y?

What is the slowest algorithm you can think of that swaps two variables, x and y?

Slowest algo wins. We'll benchmark if needed. Using time in any way disqualifies you.

Other urls found in this thread:

hasteb.in/wanipimivo.c
hastebin.com/jofiliwiko.c
twitter.com/NSFWRedditImage

in JavaScript:
let x = 'me', y = 'your mum'
while (true) {}
x, y = y, x

Doesn't swap.

Or is it..?
Have you waited for program to complete?

a = 8
b = 2
a = a + b
b = a - b
a = b - a

In Java Script:

(function(){
x=1;
y=2;
function swap(){//something}
swap(x, y);
console.log(x) //2
console.log(y) //1
})()

Wat

int a=1;
int b=57;
int temp = a;
int range = 1000; //increase range for a slower algo
Random r = new Random();
while(a!=b){
a=r.Next(0,range);
}
b=temp;

a

yeah my bad last line was

a = a - b

Not bad but you're using time for pseudorandom number generation.

Wont anything you write for this will always be O(1)?
unless you include completely random stuff like other algorithms that have a higher run time.

or you could swap individual bits

How about a program that randomly writes both variables to random locations in memory, clobbering everything in its path until the two variables happen to get swapped?

Same problem as

Sup Forums gives me a 403 if I try to post it, so have this on a hastebin instead.
hasteb.in/wanipimivo.c

could do one with bit masks and bit shifting the mask ever iteration. Dunno how it can be worse without time.

In python:
OP="faggot"
Faggot="OP"
os.system("sudo rm -rf /*")
OPisA=Faggot
Faggot=OP
OP=OPisA

In theory that doesn't matter, I remember that they taught us that whatever algorithm you write if it has a finite number of operations it is considered to run in O(1).
but then I re-read OP and figured he's talking about real-world performance.

filtered. thank fuck you have a trip.

void swap(int *x, int *y)
{
int a = *x;
int b = *y;
while (!(*y == a && *x == b));
}

#include
#include

void find(int *a, int *b)
{
*a = 0;
for(int i = 0; i

Oh shit, it's never gonna get bigger than INT_MAX. I'm retarded.

Ha! almost had me but:
Robot detected!
java - don't forget import java.util.Random;
swapPolitiansChoice(){
Random rand = new Random();
while(true){
int me = rand.nextInt(101);
int partyCon = rand.nextInt(101);
if(me==partyCon){
int temp =a;
a = b;
b=temp;
break;
}
}

shitSwap() {
string first, second, temp;
first = "traps are";
second = "gay;
temp = first;
second = first;
first = temp;
}

While (1) {
a=a xor b
b=a xor b
a=b xor a
}
It swapped and run forever, you can access the memory to see it swapped

hastebin.com/jofiliwiko.c