• + 0 comments

    Hints: Get the 6x6 transfer probability matrix

    P[i,j] := Pr(d[n+1]=i | d[n]=j).
    

    Calculate and store P^n and S[n]=I+P+P^2+...+P^n for all n=1..N in O(N) time.

    When calculating the variance, beware that the formula

    var(X) = <X^2> - <X>^2
    

    has loss-of-significance issues due to cancelation of large quantities.