Help:=proc(): print(`LD(p,x), GGR(p,x,i,N), MG(p,x,i,N,K) `): end: #Given a loaded die whose gen. function is p(x) #(prob. of having a step of size i is the coeff. of #x^i in p(x). For example, for a fair coin it is #(1/2)*x+(1/2)*x^(-1). For a fair die #(1/6)*(x+x^2+x^3+x^4+x^5+x^6) LD:=proc(p,x) local P,N,L,i,L1,j,r,ra: if {seq(evalb( coeff(p,x,i)>=0) ,i=ldegree(p,x)..degree(p,x))}<> {true} then RETURN(FAIL): fi: if {seq(type(coeff(p,x,i),rational) ,i=ldegree(p,x)..degree(p,x))}<> {true} then RETURN(FAIL): fi: P:=expand(p/subs(x=1,p)); N:=lcm( seq( denom( coeff(P,x,i) ) ,i=ldegree(P,x)..degree(P,x))): L:=[]: for i from ldegree(P,x) to degree(P,x) do if coeff(P,x,i)<>0 then L:=[op(L), [i, N*coeff(P,x,i)]]: fi: od: ra:=rand(1..N): L1:=[seq( L[i][2], i=1..nops(L))]: L1:=[ seq( add(L1[j],j=1..i) , i=1..nops(L1))]: r:=ra(): for j from 1 while L1[j]=N dollars #The output is either or N, followed by #the duration of the game GGR:=proc(p,x,i,N) local m,c: c:=0: m:=i: while m>0 and m= N then w:=w+1: fi: c:=c+g[2]: od: evalf(w/K),evalf(c/K): end: