I'm not entirely sure if this belongs here, so feel free to move/close it, if necessary.
The other day, in our PHP class, our teacher gave us a challenge used by a friend of his in job interviews. It works in every programming language, so it's not limited to PHP. He said that his friend uses this 'riddle' to weed out the people who can't think of a fast answer when it comes to logical challenges. The people that don't solve it won't get a job, of course.
The riddle is as follows:
$a = 3; $b = 7; echo "a = $a"; // has to become 7 echo "<br />"; echo "b = $b"; // has to become 3
You basically have to switch the contents of both variables without doing lame things like
$b = $a + 4. You cannot use a temporary variable either! I struggled with this, I have to admit that; I was like 'oooh yeah' when we finally got the answer.
I don't want to spoil this for anyone, so instead of posting the solution I'll just put a link.
Now, as for my question. I was wondering if there are more riddles like these out there, that people (that's you, SO) use in job interviews, etc. Perhaps even a bit harder than this one. My goal is to train my logical thinking a bit and get better in solving issues like this. Perhaps there are any books or websites out there devoted to stuff like this?