- This topic has 7 replies, 6 voices, and was last updated 21 years, 11 months ago by .
Viewing 8 posts - 1 through 8 (of 8 total)
Viewing 8 posts - 1 through 8 (of 8 total)
- You must be logged in to reply to this topic.
Home › Forums › Archives › Community Center › The BigBlueBall Lounge › School of Hackers
This is the first question on the Moscow school of hackers. I solved it in around 30 seconds.
You have integers x and y, you need to switch their values. You cannot use any other space in the memory except those two.
If you answer it, make sure to use the [ /spoiler] tags, and no syntax please.
Took me 4mins. =)
Took me about 30 seconds too…
[SPOILER]int x = 4, y = 5;
x = x + y;
y = x – y;
x = x – y;[/SPOILER][/CODE][CODE]int x = 4, y = 5;
x = x + y;
y = x – y;
x = x – y;[/CODE]
Your solution is right DJHyperbyte.
Dave is also correct.
Edit: Mistake
I don’t get it – where is Dave’s answer?
Actually it works fine.
int x = 4, y = 5;
x = x + y;
y = x – y;
x = x – y;
Took me 20-25 mins, but I got it.
There’s no point in putting the answer up, it’s already there. So just trust me 😉
hmmmm…. that was easy enough, took me about a minute… though I was wierd and did it the opposite way to DJ and Dave :p
And i’m completely useless at compueter programming and stuff… however this is question 1 of the test… I expect I would be completely stuck on question 2, it looks like a standard easy starter question.
y= x + y
x= y – x
y= y – x