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: world series

this probably isn't the cleanest solution, but...

a dynamic-programming type solution is:

(1) Create a 5x5 matrix P.

So, P[i,j] holds your pile of money when the yanks have won i games and the mets have won j games.

initialize P[4,j] := 20 for j from 0 to 3 initialize P[i,4] := 0 for i from 0 to 3

fill P in bottom-right to top left by averaging bottom and right adjacent cells:

P[i,j] := (P[i+1,j]+P[i,j+1]) / 2

(2) Make another 5x5 matrix, B, which represets your bet at any-time.

So, B[i,j] represents your bet when the yanks have won i games and the Mets j games.

fill this top-left to bottom right by:

B[i,j] = P[i+1,j] - P[i,j]

(3) Look in matrix B for your bet at any time.

The final matricies are:

Pile-Matrix

0.00

1.00

2.00

3.00

4.00

0

10.00

6.88

3.75

1.25

0.00

1

13.13

10.00

6.25

2.50

0.00

2

16.25

13.75

10.00

5.00

0.00

3

18.75

17.50

15.00

10.00

0.00

4

20.00

20.00

20.00

20.00

Bet-Matrix

0

1

2

3

4

0

3.13

3.13

2.50

1.25

1

3.13

3.75

3.75

2.50

2

2.50

3.75

5.00

5.00

3

1.25

2.50

5.00

10.00

4


 



home | software development | bug tracking software | archive

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