> #ok to post ; > #Yifan Zhang, 10/27/2020 ; > ; > #Q1. ; > #Using the same methods in procedures KtG and KiG in ComboProj1.txt, write analogous procedures RoG(k,n), for the graph of a rook on a k by n chess-board, and use SAWnu(G), to find the first few terms of the number of Hamiltonian cycles in a 3 by n chessboard. Is it in the OEIS? ; > ; > RoG:= proc(k,n) local V,E, Neighs, i,j, T1, pt, Moves,m, S1, S2, S, g,h: > 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]: S1:={seq(g, g=(-1*n-1)..-1)} union {seq(h, h=1..n-1)}: S2:={seq(g, g=(-1*k-1)..-1)} union {seq(h, h=1..k-1)}: S:= {seq([0, g], g in S1)} union {seq([h,0], h in S2)}: > Moves:=S: > 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: > ; > RoG(2,3) [{2, 3, 4}, {1, 3, 5}, {1, 2, 6}, {1, 5, 6}, {2, 4, 6}, {3, 4, 5}], [[1, 1], [1 , 2], [1, 3], [2, 1], [2, 2], [2, 3]] ; > RoG(3,5) [{2, 3, 4, 5, 6, 11}, {1, 3, 4, 5, 7, 12}, {1, 2, 4, 5, 8, 13}, {1, 2, 3, 5, 9, 14}, {1, 2, 3, 4, 10, 15}, {1, 7, 8, 9, 10, 11}, {2, 6, 8, 9, 10, 12}, {3, 6, 7 , 9, 10, 13}, {4, 6, 7, 8, 10, 14}, {5, 6, 7, 8, 9, 15}, {1, 6, 12, 13, 14, 15} , {2, 7, 11, 13, 14, 15}, {3, 8, 11, 12, 14, 15}, {4, 9, 11, 12, 13, 15}, {5, 10, 11, 12, 13, 14}], [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [2, 1], [2, 2], [2, 3], [2, 4], [2, 5], [3, 1], [3, 2], [3, 3], [3, 4], [3, 5]] ; > ; > SAWnu:=proc(G) local i: > add(SAW1nu(G,1,G[1][i],nops(G)-1,{}),i=1..nops(G[1])): > end: > SAW1nu:=proc(G,a,b,k,S) local mu,n,a1: > option remember: > n:=nops(G): > if not (1<=a and a<=n and 1<=b and b<=n) then > RETURN(FAIL): > fi: > > if k=1 then > if member(b,G[a]) and not member(a,S) and not member(b,S) then > RETURN(1): > else > RETURN(0): > fi: > fi: > > > if (member(a,S) or member(b,S)) then > RETURN(0): > fi: > > mu:=G[a] minus (S union {a}): > > add(SAW1nu(G,a1,b,k-1,S union {a}), a1 in mu): > > end: > ; > seq(SAWnu(RoG(3,i)), i=1..6) 2, 6, 96, 3132, 252240, 36307440 ; > #Not in OEIS ; > ; > ; > #Q2. ; > #Start exploring ComboProj2.txt, and use it to find the number of ways of walking from [0,0] to [40,40] with atomic steps {[1,0],[0,1],[1,1],#[2,2]} > #How many of these never go above x=y? > > #Start exploring ComboProj3.txt, and use it to find the first 20 terms of of the sequence enumerating walks from [0,0,0] to [n,n,n] with #atomic steps {[1,0,0],[0,1,0],[0,0,1],[1,1,1]}. What is the corresponding sequence for those walks that stay in x ≥ y ≥ z ? ; > # ; > NuW:=proc(Pt,A) local a: > option remember: > > if Pt[1]<0 or Pt[2]<0 then > RETURN(0): > elif Pt=[0,0] then > RETURN(1): > else > add(NuW(Pt-a,A),a in A): > fi: > end: > NuGW:=proc(Pt,A) local a: > option remember: > > if (Pt[1]<0 or Pt[2]<0 or Pt[1] RETURN(0): > elif Pt=[0,0] then > RETURN(1): > else > add(NuGW(Pt-a,A),a in A): > fi: > end: > a:=NuW([40,40], {[1,0], [0,1], [1,1], [2,2]}) Typesetting:-mprintslash([(a := 2382564832244243056285491057263)],[ 2382564832244243056285491057263]) ; > b:=NuGW([40,40], {[1,0], [0,1], [1,1], [2,2]}) Typesetting:-mprintslash([(b := 89322096703094945357683861273)],[ 89322096703094945357683861273]) ; > a-b 2293242735541148110927807195990 ; > #there are 2293242735541148110927807195990 paths that never go above x=y ; > ; > SeqGW:=proc(A,K) local i: > [seq(NuGW([i,i,i],A),i=1..K)]: > end: > SeqW:=proc(A,K) local i: > [seq(NuW([i,i,i],A),i=1..K)]: > end: > NuGW:=proc(Pt,A) local a: > option remember: > > if (Pt[1]<0 or Pt[2]<0 or Pt[3]<0 or Pt[1] RETURN(0): > elif Pt=[0,0,0] then > RETURN(1): > else > add(NuGW(Pt-a,A),a in A): > fi: > end: > NuW:=proc(Pt,A) local a: > option remember: > > if Pt[1]<0 or Pt[2]<0 or Pt[3]<0 then > RETURN(0): > elif Pt=[0,0,0] then > RETURN(1): > else > add(NuW(Pt-a,A),a in A): > fi: > end: > SeqGW({[1,0,0],[0,1,0],[0,0,1],[1,1,1]}, 20) [2, 10, 88, 1043, 14778, 236001, 4107925, 76314975, 1491934038, 30389576308, 640286048416, 13877540824735, 308102204007536, 6983346070924707, 161156356282624227, 3778249609096250059, 89826197363219012470, 2162338803354415120414, 52637415804379149938876, 1294313658632145337351381] ; > SeqW({[1,0,0],[0,1,0],[0,0,1],[1,1,1]},20) [7, 115, 2371, 54091, 1307377, 32803219, 844910395, 22188235867, 591446519797, 15953338537885, 434479441772845, 11927609772412075, 329653844941016785, 9163407745486783435, 255982736410338609931, 7181987671728091545787, 202271071826031620236525, 5715984422606794841997001, 162016571360163769411597081, 4604748196249289767697705221] ; > ; > ; > ; > ; > ; > ; > ; > ; > ;