A couple guys here at work have been working on some puzzles. They didn't like my solution to the 3rd puzzle, as they wanted it to be more math base and not like programming. Here are the puzzles:
Assume: a and b are positive integers. (
I think this condition only matters for the third puzzle)
1. Given a and b, how do you swap the values without using a third temporary variable?
2. Given a, what is the function to make b = a+1 if a is odd, and b=a-1 if a is even? You are not allowed to use conditional statements.
3. Given a and b, what is the function to make c=max(a,b) without using conditional statements?
Posted by
Jon Daley on
October 6, 2004, 11:11 am
| Read 2604 times
|
Comments
(6)
Category
General:
[
first]
[
previous]
[
next]
[
newest]