Game Description Player 1: Decides on integer x > 0 Player 2 : Has to find a number yn so that yn x Rules: Player 2: y1< y2< …< yn y1< y2< …< yn-1 < x and yn x On a guess yj, player 1 either says: smaller than x, please provide a next guess larger or equal x, and reveals x stopping the game Optimization Criteria Let the guesses be y1, y2, ….yn, so that yn x yj < x for all j n – 1 The optimization criteria is the performance ratio: y j x j Programming Examples 1. Write a C program that randomly generates the number to guess and ask user to provide the guesses. The program will calculate and print the performance ratio for one game 2. Write a C program that randomly generates the number to guess and ask user to provide the guesses. The program will calculate and print the performance ratio for 10 games and also calculates the average of performance ratios for 10 games. 3. Modification of example 2: let user decide on amount of games that user would like to play and output the average performance ratio over all games. EXAMPLE Player 1 Player 2 x is chosen, please provide a guess Smaller than x, next guess Smaller than x, next guess Smaller than x, next guess Smaller than x, next guess STOP! x = 37 1 3 10 28 76 Performance Ratio 118 / 37 = 3.189189 EXAMPLE Player 1 Player 2 x is chosen, please provide a guess Smaller than x, next guess Smaller than x, next guess Smaller than x, next guess Smaller than x, next guess STOP! x=5 1 2 3 4 23 Performance Ratio (1+2+3+4+23) / 5 = 6.6 The Powers of 2 Strategy for the Second Player It turns out that the simple strategy that selects powers of 2: y0 = 1, y1 = 2, y2 = 4, … yi = 2i … is an optimal deterministic strategy for this game The worst case for the strategy is when the number selected by the first player is x = 2j + 1 In this case the game is played until the second player suggests 2j+1 EXAMPLE x = 13 guesses: 1, 2, 4, 8, 16 sum: 1+2+4+8+16 = 31 performance ratio is 2.384615 x = 65 guesses: 1, 2, 4, 8, 16, 32, 64, 128 sum: 1+2+4+8+16+32+64+128 = 255 performance ratio is 3.923 A Randomized Strategy The following simple randomized strategy gives an improved expected value Let R [0, 1) – randomly and uniformly chosen from interval [0, 1) Define yj = exp( j + ) Let i be so that exp( i - 1 + ) < x exp( i + ) The expected performance ratio is: e x 1 e x EXAMPLE Player 1 Player 2 x is chosen, please provide a guess Smaller than x, next guess Smaller than x, next guess Smaller than x, next guess Smaller than x, next guess STOP! x = 48 = 0.419 exp() = 1 exp(+1) = 4 exp(+2) = 11 exp(+3) =30 exp(+4) = 83 Performance Ratio 129 / 48 = 2.6875 EXAMPLE Player 1 Player 2 x is chosen, please provide a guess Smaller than x, next guess Smaller than x, next guess Smaller than x, next guess Smaller than x, next guess STOP! x = 63 = 0.866 exp() = 2 exp(+1) = 6 exp(+2) = 17 exp(+3) =47 exp(+4) = 129 Performance Ratio 201 / 63 = 3.190476 EXAMPLE Player 1 Player 2 = 0.195 x is chosen, please provide a guess Smaller than x, next guess Smaller than x, next guess STOP! x=6 exp() = 1 exp(+1) = 3 exp(+2) = 8 Performance Ratio 12 / 6 = 2.0000 Discussion Questions Discussion of the Optimization Criteria selection: Why not to choose yi/x, where yi x? Answer: simple strategy 1, 2, 3, …is optimal Discussion of possible strategies: Why not to start with some “large” number? Why do we not benefit from increasing the next guess only a little compared to the previous guess? What is the disadvantage of making the next guess, say, 100 times larger than previous guess?
© Copyright 2026 Paperzz