techInterview
Answers to technical interview questions - accepting donations for dogs

 
home
faq
reading
feedback
discuss
archive
fogcreek
bug tracking
pets in ny
petfinder



*new* techInterview bible


thank your brain
save a dog's life




 

Solved by Thomas W. Millett

solution: duel

You have 3 options to consider:

(1) Shoot at 50% guy. Death comes with: 72% likilhood (2) Shoot at the 100% guy. Death comes with: 63.64% likihood (3) Shoot into the air (purposely miss). Death comew with 58.33% likihood.

So, you shoot into the air and hope for the best.

Calculations:

The p in the probabilities below represents your probability of dying at some point if you MISS either guy in the first round. It'll be filled in later.

(1) if you shoot at the 50% guy and get him, you're guaranteed to get shot the next round.

prob of dying at some point by aiming at the 50% guy:

(=) (33.3%)(100%)+(66.67%)*(p)

(=) (33.3%)+(66.67%)(p)

(2) if you shoot at the 100% guy and get him, you're left with this geometric sum of probability of getting shot by the 50% guy at some point in the future...it converges.

(=) [(50%)] +

[(50%)(66.67%)(50%)] +

[(50%)(66.67%)(50%)(66.67%)(50%)] + ...

(=) 50% * { 1 + (1/3) + (1/3)^2 + ... }

(=) 50% * {3/2)

(=) 75%

so, your prob of getting shot if you shoot at the 100% guy is:

(=) (33.3%)(75%)+(66.67%)(p)

(=) (24.75%) + (66.67%)(p)

still crummy, but it dominates the alternative, for positive p.

(3) What happens if you miss? ie, what's (p)?

if you miss, the second guy has a choice to make...does he shoot at you, or the other guy? his options:

(1) Shoot you: if he gets you, he's guaranteed to die on the next shot.

if he misses, he has q chance of dying (which we'll get later).

(=) (50%)(100%)+(50%)(q)

(=) (50%)+(0.5)(q)

(2) Shoot at the 100% dude:

If he gets the 100% guy, there some infinite sum representing his probability of getting shot by you:

[(33.33%)] +

[(66.67%)(50%)(33.33%)] +

[(66.67%)(50%)(66.67%)(50%)(33.33%)] + ...

(=) 33.33% * [ 1 + (1/3) + (1/3)^2 + ... ]

(=) 33.33% * [(3/2)]

(=) (50.0%)

So, he chances of getting shot if he shoots at the 100% guy are:

(=) (50%)*(50%) + (50%)(q)

(=) (25%)+(.5)q

No matter what q is, he'd prefer shooting the 100% guy to shooting you.

Now, what happens if *he* misses (the 100%) guy? ie, what's q? if he misses, then the 100% guy has to make a decision:

(1) Shoot you:

he's guaranteed to get you, so his chances of dying are just 50%. (game ends after the next round...the 50% gets only one shot)

prob of dying: 50%

(2) Shoot the 50% guy:

by the same logic, he'd have a 33.33% chance of death (getting shot by you).

So, he prefers to shoot the 50% guy.

So, q is 100% (ie, if the 50% guy misses, the 100% guy shoots him immediately). From that, we know the 50% guy's optimal move, if everyone's around on his first shot. He'd prefer shooting at the 100% guy to shooting at you or purposely missing.

Now, we need to get p, which is our probability of dying if we purposely miss either guy (shoot into the air).

We know the 50% guy shoots at the 100% guy if we miss.

(1) With 50% probability, the 50% guy kills the 100% guy, resulting in a shootout b/w us and the 50% guy.

(=) (50%) * [ (66.67%)*(50%) + (66.67%)*(50%)*(66.67%)(50%) + ...

(=) (50%) * [ (1/3) + (1/3)^2 + ... ]

(=) (50%) * [0.5]

(=) (25%)

(2) He misses him. Then, we get one shot at the 100% guy (after the 100% guy shoots the 50% guy).

Our chances of death are:

(50%)*(66.67%) = (33.33%)

So, p is (25%)+(33.33%) = 58.3%

So, again, our three choices are

(1) Shoot at 50% guy. Death comes with:

(=) (33.3%)+(66.67%)(p)

(=) 72% likilhood

(2) Shoot at the 100% guy. Death comes with:

(=) (24.75%) + (66.67%)(p)

(=) 63.64% likihood

(3) Shoot into the air (purposely miss).

(=) p

(=) 58.33% likelihood.


 



home | software development | bug tracking software | archive

[general software discussion] [dogs new york city] [Software Quality]