#OK to post homework #Blair Seidler, 2021-02-14, Assignment 6 with(combinat): Help:=proc(): print(`GNuWalks2D(A,pt)`,`GRandWalk2D(A,pt)`): print(`NuWalkskD(A,pt)`,`GNuWalkskD(A,pt)`): end: # 1. #GNuWalks2D(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 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]] GNuWalks2D:=proc(A,pt) local i,W,W1,w: option remember: if pt[1]<0 or pt[2]<0 or pt[1]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 NuWalkskD:=proc(A,pt) local k,i,W,W1,w: option remember: k:=nops(pt): if not ({seq(evalb(pt[i]>=0),i=1..k)}={true}) then RETURN(0): fi: if add(op(pt))=0 then RETURN(1): fi: W:=0: for i from 1 to nops(A) do W1:=NuWalkskD(A,pt-A[i]): W:=W + W1: od: W: end: #GNuWalkskD(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 GOOD (subdiagonal) WALKS from [0,0,...] to #to pt, described by giving the intermedite location GNuWalkskD:=proc(A,pt) local k,i,W,W1,w: option remember: k:=nops(pt): if not (({seq(evalb(pt[i]>=0),i=1..k)}={true}) and ({seq(evalb(pt[i]>=pt[i+1]),i=1..k-1)}={true})) then RETURN(0): fi: if add(op(pt))=0 then RETURN(1): fi: W:=0: for i from 1 to nops(A) do W1:=GNuWalkskD(A,pt-A[i]): W:=W + W1: od: W: end: #(i) seq(NuWalkskD([[1,0,0],[0,1,0],[0,0,1]],[i,i,i]),i=1..10): #6, 90, 1680, 34650, 756756, 17153136, 399072960, 9465511770, 227873431500, 5550996791340 #A006480 DeBruijn's S(3,n): (3n)!/(n!)^3 #(ii) seq(GNuWalkskD([[1,0,0],[0,1,0],[0,0,1]],[i,i,i]),i=1..10): #1, 5, 42, 462, 6006, 87516, 1385670, 23371634, 414315330, 7646001090 #A005789 3-dimensional Catalan numbers #(iii) seq(NuWalkskD([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]],[i,i,i,i]),i=1..10): #24, 2520, 369600, 63063000, 11732745024, 2308743493056, 472518347558400, #99561092450391000, 21452752266265320000, 4705360871073570227520 #A008977 a(n)=(4n)!/(n!)^4 #(iv) seq(GNuWalkskD([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]],[i,i,i,i]),i=1..10): #1, 14, 462, 24024, 1662804, 140229804, 13672405890, 1489877926680, 177295473274920, #22661585038594320 #A005790 4-dimensional Catalan numbers #### Code included from C6.txt #### 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]