Post Reply 
Question about a simple game
04-23-2019, 11:05 PM (This post was last modified: 04-24-2019 01:55 AM by Albert Chan.)
Post: #3
RE: Question about a simple game
(04-23-2019 08:09 PM)Namir Wrote:  I = 0.5*T^2 + T = T*(T/2 + 1)

That can't be right ... If T=1, expected iterations *only* 1½ ?

Tried Lua simulation, expected iterations vary so much that the linear term can not be predicted.

Code:
function loops(t)
    local n, sum, r, abs = 0, 0, math.random, math.abs
    repeat sum = sum + r() - r(); n=n+1 until abs(sum) >= t
    return n
end

function average(f, t, n) -- above vary too much, so do average of loops
    local sum = 0
    for i=1,n do sum = sum + f(t) end
    return sum / n
end

lua> average(loops, 10, 1000) -- 5 times: 640 633 651 584 628 ≈ 627
lua> average(loops, 20, 1000) -- 5 times: 2450 2433 2360 2492 2438 ≈ 2435
lua> average(loops, 40, 1000) -- 5 times: 9606 9680 9687 9690 10083 ≈ 9749

9749 / 2435 = 4.00, so curve shape should be N = K T^2
K = N/T^2 = 9749 / 40^2 = 6.093
N = 6.093 T^2

However, for small T, the curve does not fit quite right.

lua> average(loops, 1, 1e6) --> Expected iterations for T=1 ~ 9.26

T/sqrt(N) = sqrt(1/6.093) = 0.405

0.405 is roughly the standard deviation of rand(0,1) - rand(0,1)

MTB > rand 1000 C1-C2;
SUBC> uniform 0 1.
MTB > let C3 = C1-C2
MTB > describe C3
Code:
                N     MEAN   MEDIAN   TRMEAN    STDEV   SEMEAN
C3           1000  -0.0311  -0.0284  -0.0333   0.4044   0.0128

              MIN      MAX       Q1       Q3
C3        -0.9574   0.9448  -0.3223   0.2442

C3 looks triangular. Below histogram from Minitab command: hist C3
Code:
    -1.0       4  *
    -0.8      46  **********
    -0.6      86  ******************
    -0.4     127  **************************
    -0.2     175  ***********************************
     0.0     182  *************************************
     0.2     171  ***********************************
     0.4     105  *********************
     0.6      68  **************
     0.8      30  ******
     1.0       6  **
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Question about a simple game - Namir - 04-23-2019, 08:09 PM
RE: Question about a simple game - Albert Chan - 04-23-2019 11:05 PM
RE: Question about a simple game - Namir - 04-24-2019, 03:15 AM
RE: Question about a simple game - Namir - 04-24-2019, 03:14 PM
RE: Question about a simple game - Namir - 04-24-2019, 03:10 PM



User(s) browsing this thread: 1 Guest(s)