04-23-2019, 08:09 PM
Hi All,
I wrote a simple game where the user plays against the calculator/PC. The game is an iterative one. In ach iteration the user and the PC generate random numbers (0,1). The user’s random value is added to a summation variable, while the calculator’s random number is subtracted from that summation variable. If the summation variable reaches or exceeds a user-chosen value T, the user is the winner. If the summation variable reaches -T or less, the the calculator win. Here is the pseudo-code:
I noticed that the average iterations, I, for either player (the user or the calculator) to win is a function of T. I used quadratic fit of I as a function of T. The curves I obtained from the numerous runs indicate that the underlying relation between I and T is:
I = 0.5*T^2 + T = T*(T/2 + 1)
My question is, can someone derive the above equation based on whatever statistical assumptions?
Namir
I wrote a simple game where the user plays against the calculator/PC. The game is an iterative one. In ach iteration the user and the PC generate random numbers (0,1). The user’s random value is added to a summation variable, while the calculator’s random number is subtracted from that summation variable. If the summation variable reaches or exceeds a user-chosen value T, the user is the winner. If the summation variable reaches -T or less, the the calculator win. Here is the pseudo-code:
Code:
Sum = 0
I = 0
Do
Me = Rand(0,1)
Sum = Sum + Me
PC = Rand(0,1)
Sum = Sum – PC
I = I + 1
Until Sum >= T or Sum <= -T
if Sum >= T Then
Show "You Win"
else
Show "You lose"
end
I noticed that the average iterations, I, for either player (the user or the calculator) to win is a function of T. I used quadratic fit of I as a function of T. The curves I obtained from the numerous runs indicate that the underlying relation between I and T is:
I = 0.5*T^2 + T = T*(T/2 + 1)
My question is, can someone derive the above equation based on whatever statistical assumptions?
Namir