#OK to post homework #Kent Mei, 11/1/20, Assignment 15 #--------------------------------- #Part 1 RoG:=proc(k,n) local V,E,i,j,T1,v,Neighs,Moves,m,pt: V:=[seq(seq(seq([i,j],j=1..n),i=1..k))]: for i from 1 to nops(V) do T1[V[i]]:=i: od: E:=[]: for i from 1 to nops(V) do pt:=V[i]: Moves:={seq([j,0],j = -k..k)} union {seq([0,j],j = -n..n)}: Moves:= Moves minus {[0,0]}: Neighs:={seq(pt+m,m in Moves)}: Neighs:= Neighs intersect convert(V,set): E:=[op(E),{seq(T1[v],v in Neighs)}]: od: E,V: end: #Sequence from n = 1..6 #[2,6,96,3132,252240,36307440] #It does not seem to be in the OEIS. #--------------------------------- #Part 2 #NuW([40,40],{[1,0],[0,1],[1,1],[2,2]}) #2382564832244243056285491057263 #is the number of ways of walking from [0,0] to [40,40] with atomic steps {[1,0],[0,1],[1,1],[2,2]}. #NuGW([40,40],{[1,0],[0,1],[1,1],[2,2]}) #89322096703094945357683861273 #is the number of those that never go above x = y. #[seq(NuW([n,n,n],{[1,0,0],[0,1,0],[0,0,1],[1,1,1]}), n = 1..20)] #[7, 115, 2371, 54091, 1307377, 32803219, 844910395, 22188235867, 591446519797, 15953338537885, 434479441772845, 11927609772412075, 329653844941016785, 9163407745486783435, 255982736410338609931, 7181987671728091545787, 202271071826031620236525, 5715984422606794841997001, 162016571360163769411597081, 4604748196249289767697705221] #[seq(NuGW([n,n,n],{[1,0,0],[0,1,0],[0,0,1],[1,1,1]}), n = 1..20)] #[2, 10, 88, 1043, 14778, 236001, 4107925, 76314975, 1491934038, 30389576308, 640286048416, 13877540824735, 308102204007536, 6983346070924707, 161156356282624227, 3778249609096250059, 89826197363219012470, 2162338803354415120414, 52637415804379149938876, 1294313658632145337351381]