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 2466 times
Category General: [first] [previous] [next] [newest]
Comments
Another puzzle from another co-worker:
There are three guys in a gun-fight, one can shoot perfectly, one guy misses one out of three times, and you, who misses two out of three times.
This is an organized fight, so only one person shoots at a time, and since you can't shoot that well, you get to go first.
Assumption 1: You want to have the best chance of walking away alive.
Assumption 2: It only takes one successful hit to kill a guy
Where do you aim?
Posted by jondaley on October 7, 2004, 10:13 am

My first impulse would be to say "at yourself" but it really seems like you want a little more info on how the rules of the fight go. IE, does everyone have one chance to shoot at one person, and the other people can't shoot at someone who has already been shot at?
Posted by Joyful on October 7, 2004, 11:37 am

I don't think you want to shoot yourself...
The fight goes from person to person, they can shoot wherever they want, once, and then the next guy goes. You keep taking turns until there is one person left.
Posted by jondaley on October 7, 2004, 2:36 pm

If each person gets only one shot, and each person can only get shot at once, then I agree with Heather. And of course there is a case to be made for the idea that it is better to be dead than a murderer...but that's another puzzle./>
Instead of shooting yourself, I say you aim into the air, and hit no one./>
A = the guy who never misses; B = the guy who hits 2 out of 3 shots. I'm assuming B shoots second, since we seem to be going in reverse order of competence. But I don't think it matters./>
You don't want to shoot B, because if you hit him, you're dead: It's A's turn to shoot, he never misses, and you are his only target. But if you kill A, B will then keep shooting at you, and he is twice the shot you are - pretty bad odds./>
Neither A nor B want to shoot at you while the other is alive, since you're such a bad shot. B can't take your way out, because A is bound to shoot him, fatally. So he has to shoot at A. If A dies, you are back where you would have been had you killed A, with this important difference: you get to shoot at B before he can shoot at you./>
If B does not kill A, A's best bet is still to kill B. Then you get at least once chance to kill A before he can kill you./>
Sounds like a pretty dangerous situation no matter how you look at it.
Posted by SursumCorda on October 7, 2004, 3:37 pm

Well, somehow I messed up the HTML, and I can't edit my comment, but I think you can still read it.
Posted by SursumCorda on October 7, 2004, 3:38 pm

I am not sure what you did in your html.
Your answer is correct. The original problem said the best guy went second, but after we thought about it, we decided it didn't matter.
Posted by jondaley on October 8, 2004, 7:03 am
Add Comment
Add comment
E-mail me when comments occur on this article

culpable-adaptable