#C1.txt, Jan. 23, 2020, ExpMath Help:=proc(): print(` MH1() , MH2(), RS(), FRun(L,k) , HotH1() `): end: #MH1(): simulating the Monty-Hall game w/o changing MH1:=proc() local ra, c,g: ra:=rand(1..3): c:=ra(): g:=ra(): evalb(c=g): end: #MH2(): simulating the Monty-Hall game with changing MH2:=proc() local ra, g,c, g1, m,S: ra:=rand(1..3): c:=ra(): g:=ra(): S:={1,2,3} minus {c,g}: m:=S[rand(1..nops(S))()]: S:={1,2,3} minus {g,m}: g1:=S[1]: evalb(g1=c): end: #RS(N): a random sequence of 0 and 1 of length N RS:=proc(N) local ra,i: ra:=rand(0..1): [seq(ra(),i=1..N)]: end: #FRun(L,k): inputs a list of length L of 0,1, and a pos.integer k, outputs the #first location (if it exists) of k consecutive 0's, or returns FAIL FRun:=proc(L,k) local i,j: for i from 1 to nops(L)-k+1 do if {seq(L[j],j=i..i+k-1)}={0} then RETURN(i+k-1): fi: od: FAIL: end: #HotH1(N,k): generates a random sequence of {0,1} of length N, finds #the end location of 0-streak of length k, and outputs right after it HotH1:=proc(N,k) local L,j: L:=RS(N): j:=FRun(L,k): if j=FAIL or j=N then RETURN(FAIL): fi: L[j+1]: end: