Discussion about math, puzzles, games and fun. Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ ¹ ² ³ °
 

You are not logged in. #1 20080227 04:35:45
variable swapping puzzlehere's something i thought of today at school Last edited by mikau (20080227 04:42:19) A logarithm is just a misspelled algorithm. #4 20080227 06:25:14
Re: variable swapping puzzleI was going to do inline assembly, bu then I remembered how much work it would be to look up register names and the like. "In the real world, this would be a problem. But in mathematics, we can just define a place where this problem doesn't exist. So we'll go ahead and do that now..." #6 20080227 09:42:10
Re: variable swapping puzzledoes this actually use less memory though? its still interesting to see things like this though is it possible to not use any extra memory? perhaps with a restriction on the values of the integers. Last edited by lucadeltodesco (20080227 09:44:04) The Beginning Of All Things To End. The End Of All Things To Come. #7 20080227 10:15:08
Re: variable swapping puzzlethe purpose of this puzzle is by no means to save memory or time, its just a puzzle for fun. Last edited by mikau (20080227 10:15:55) A logarithm is just a misspelled algorithm. #8 20080228 00:09:07
Re: variable swapping puzzleI'd be wary of using that one line solution, since it can be interpretted two different ways by the compiler. If it evaluates right to left then it will set x = y first, then subtract that from x + y, which is now y + y, and you'll end up with y = y and x = y. Of course, I realize that you aren't suggesting actually using such code, but I thought that should be pointed out. Wrap it in bacon #9 20080228 08:19:26
Re: variable swapping puzzle
I suppose it might be interpreted different ways by different compilers, but my understanding of parenthesis is that inner most parens are always evaluated first, thats why i have doubled parens around x + y. So I'm PRETTY sure this would work on any correct compiler. A logarithm is just a misspelled algorithm. 