#C6.txt: Maple code for Lecture 6 of ExpMath by Dr.Z. Help6:=proc(): print(`LD(L) , Walks2D(A,pt) , NuWalks2D(A,pt), FootBall()`): print(`RandWalk2D(A,pt)`): end: #Walks2D(A,pt): Inputs a list A of `atomic' steps A #in the form [a,b] (with a,b non-neg. and a+b>0) and #a final location (final score in game, e.g. [31,9]). #OUTPUTS the SET of all WALKS from [0,0] to #to pt, described by giving the intermedite location #[[0,0],[2,0],[10,0],[10,2],[10,10]] Walks2D:=proc(A,pt) local i,W,W1,w: option remember: if pt[1]<0 or pt[2]<0 then RETURN({}): fi: if pt=[0,0] then RETURN({[[0,0]]}): fi: W:={}: for i from 1 to nops(A) do W1:=Walks2D(A,pt-A[i]): W:=W union {seq([op(w),pt], w in W1)}: od: W: end: FootBall:=proc(): [[0,2],[0,3],[0,6],[0,7],[0,8],[2,0],[3,0],[6,0],[7,0],[8,0]]: end: #NuWalks2D(A,pt): Inputs a list A of `atomic' steps A #in the form [a,b] (with a,b non-neg. and a+b>0) and #a final location (final score in game, e.g. [31,9]). #OUTPUTS the NUMBER of all WALKS from [0,0] to #to pt, described by giving the intermedite location #[[0,0],[2,0],[10,0],[10,2],[10,10]] NuWalks2D:=proc(A,pt) local i,W,W1,w: option remember: if pt[1]<0 or pt[2]<0 then RETURN(0): fi: if pt=[0,0] then RETURN(1): fi: W:=0: for i from 1 to nops(A) do W1:=NuWalks2D(A,pt-A[i]): W:=W + W1: od: W: end: #RandWalk2D(A,pt): inputs a list of atomic steps A and # a final destination pt, outputs UNIFORMLY at random #a walk from [0,0] to pt using the steps in A RandWalk2D:=proc(A,pt) local i,W1,Die1,r: if pt[1]<0 or pt[2]<0 then RETURN(FAIL): fi: if pt=[0,0] then RETURN([[0,0]]): fi: Die1:=[seq(NuWalks2D(A,pt-A[i]),i=1..nops(A))]: #Let r be the index in A of the last step in our uniform-random walk #that ended at pt r:=LD(Die1): W1:=RandWalk2D(A,pt-A[r]): [op(W1),pt]: end: ##start GOOD (subdiagonal walks) #GWalks2D(A,pt): Inputs a list A of `atomic' steps A #in the form [a,b] (with a,b non-neg. and a+b>0) and #a final location (final score in game, e.g. [31,9]). #OUTPUTS the SET of all GOOD (subdiagonal) WALKS from [0,0] to #to pt, described by giving the intermedite location #[[0,0],[2,0],[10,0],[10,2],[10,10]] GWalks2D:=proc(A,pt) local i,W,W1,w: option remember: if (pt[1]<0 or pt[2]<0 or pt[1]