> #Weiji Zheng, 11/01/2020, Assignment15 ; > #OK TO POST HOMEWORK ; > ; > ; > ; > #Q1 ; > ; > RoG := proc(k,n) local V,E,i,j,T1,v,Neighs,Moves,m,pt,s1,s2,s3,s4,a,b: > > #The set the list of vertices in the k by n board (using matrix indexing) > V:=[seq(seq(seq([i,j],j=1..n),i=1..k))]: > > #T1 is a labelling of the vertices in V > > for i from 1 to nops(V) do > T1[V[i]]:=i: > od: > > #E is a list such that its i-th entry is the set of neighbors of V[i] using the above-indexing > > E:=[]: > > for i from 1 to nops(V) do > pt:=V[i]: > > #Moves:={[1,0],[-1,0],[0,1],[0,-1],[1,1],[-1,-1],[1,-1],[-1,1]}: > s1 := seq([a, 0], a = 1 .. k): > > s2 := seq([-a, 0], a = 1 .. k): > > s3 := seq([0, b], b = 1 .. n): > > s4 := seq([0, -b], b = 1 .. n): > > Moves := {s1,s2,s3,s4}: > #There are up to 8 neighbors of any vertex > Neighs:={seq(pt+m,m in Moves)}: > > #But many of them fall off the board, > Neighs:=Neighs intersect convert(V,set): > > #We append to the "list of neighbors" the set of neighbors of the current vertex BUT in terms of their "ids" (given by T1) > #getting a description of the graph in "cannical form" > E:=[op(E),{seq(T1[v],v in Neighs)}]: > od: > > #We return the graph in "canonical form" where the vertices (members of V), are labelled by positive inetegers from 1 to nops(V) > #together with the "dictionary" > E,V: > end: > ; > #seq(SAWnu(RoG(3,i)), i=1..6) = 2, 6, 96, 3132, 252240, 36307440 ; > #NOT FOUND IN OEIS ; > ; > #Q2 ; > #1. ; > #USE SeqW ; > 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: > SeqW:=proc(A,K) local i: > [seq(NuW([i,i],A),i=1..K)]: > end SeqW := proc (A, K) local i; [seq(NuW([i, i], A), i = 1 .. K)] end proc ; > SeqW({[0, 1], [1, 0], [1, 1], [2, 2]}, 40) [3, 14, 71, 379, 2082, 11651, 66051, 378064, 2180037, 12644861, 73695358, 431209313, 2531556197, 14904832196, 87970766447, 520337606401, 3083584244460, 18304476242735, 108820740004749, 647817646760368, 3861215365595659, 23039691494489015, 137615812845579390, 822738993163308691, 4922949521986023963, 29480139394909356044, 176664398792213185409, 1059402929496079389631, 6356902648489583020308, 38166637970127629445209, 229276573792993574603787, 1378027658578343598968422, 8286384291210047832045023, 49850407222197537838691609, 300025068023888975708739560, 1806430285705003018542769435, 10880533315007764522316552713, 65559512416370766384694103782, 395157036800184178672318869369, 2382564832244243056285491057263] ; > #2382564832244243056285491057263 ; > ; > #2. ; > #USE SeqGW ; > 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: > SeqGW:=proc(A,K) local i: > [seq(NuGW([i,i],A),i=1..K)]: > end: > SeqGW({[0, 1], [1, 0], [1, 1], [2, 2]}, 40) [2, 7, 27, 116, 532, 2554, 12675, 64507, 334836, 1765833, 9434779, 50962640, 277839361, 1526834471, 8448751385, 47035469902, 263260232668, 1480527858436, 8361881707770, 47409359120684, 269736194796537, 1539547726712437, 8812663513352489, 50579825742416942, 291012706492224315, 1678146650028389023, 9697482307486861125, 56148049483650883418, 325685956663306169704, 1892343209238706561552, 11012606961635116334631, 64184027732131247229285, 374603199042488986947084, 2189213854778309191457243, 12809866709764967142650533, 75043134255268720569687608, 440108608055424139245905601, 2583842686807144572684013803, 15184702028756125034970193936, 89322096703094945357683861273] ; > #89322096703094945357683861273 ; > ; > #3. ; > #USE THE NEW SeqW ; > 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: > SeqW:=proc(A,K) local i: > [seq(NuW([i,i,i],A),i=1..K)]: > end: > SeqW({[0, 0, 1], [0, 1, 0], [1, 0, 0], [1, 1, 1]}, 20) [7, 115, 2371, 54091, 1307377, 32803219, 844910395, 22188235867, 591446519797, 15953338537885, 434479441772845, 11927609772412075, 329653844941016785, 9163407745486783435, 255982736410338609931, 7181987671728091545787, 202271071826031620236525, 5715984422606794841997001, 162016571360163769411597081, 4604748196249289767697705221] ; > ; > ; > #4. ; > #USE THE NEW SeqGW ; > 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: > SeqGW:=proc(A,K) local i: > [seq(NuGW([i,i,i],A),i=1..K)]: > end: > SeqGW({[0, 0, 1], [0, 1, 0], [1, 0, 0], [1, 1, 1]}, 20); [2, 10, 88, 1043, 14778, 236001, 4107925, 76314975, 1491934038, 30389576308, 640286048416, 13877540824735, 308102204007536, 6983346070924707, 161156356282624227, 3778249609096250059, 89826197363219012470, 2162338803354415120414, 52637415804379149938876, 1294313658632145337351381] ; > ;