Help:=proc(): print(`New:`); print(`g2F(i,j),Wyt(i,j),CD(N)`); print(`From Apr22.txt`); print(`mex(S), g(G), g2(i,j) `): print(` g2(i,j) `): end: #============================================================= #g2F(i,j): computes the nim sum of i and j g2F := proc(i,j) local L1,L2,s; L1 := convert(min(i,j),base,2); L2 := convert(max(i,j),base,2); L1 := [op(L1),0$(nops(L2)-nops(L1))]; s := L1+L2 mod 2; RETURN(add(s[k]*2^(k-1),k=1..nops(s))); end: #============================================================= #Wyt(i,j): computes the grundy function of Wytoff's game #with first pile of size i and second pile of size j Wyt := proc(i,j) option remember; if i=0 and j=0 then RETURN(0); else RETURN(mex({seq(Wyt(i-i1,j),i1=1..i), seq(Wyt(i,j-j1),j1=1..j), seq(Wyt(i-k,j-k),k=1..min(i,j))})); fi; end: #============================================================= #CD(N): inputs a positive integer N and outputs a list L such #that L[k+1] is the list of positions with Grundy function #exactly k, for all positions [i,j] with i+j<=N CD := proc(N) local T,i,j,r,S,gv,ma,k; #T[i]={[i1,i2]: Wyt(i1,i2)=i} gv := {}; for r from 0 to N do for i from 0 to r do for j from i to r-i do S[i,j]:=Wyt(i,j); gv := gv union {S[i,j]}; od; od; od; ma := max(gv); for k from 0 to ma do T[k] := []; od; for r from 0 to N do for i from 0 to r do T[S[i,r-i]] := [op(T[S[i,r-i]]),[i,r-i]]; od; od; RETURN([seq(T[i],i=0..ma)]); end: #============================================================= Wyt0 := proc(m) local phi; phi := (1+sqrt(5))/2; [seq([trunc(i*phi),trunc(i*phi+i)],i=0..m)]; end: ################### From Apr22.txt ####################### mex:=proc(S) local i: for i from 0 while member(i,S) do od: i: end: #g(G): given a directed graph G in the data structure #where the set of vertices is {1, ..., nops(G)} and #G[i] is the set of vertices reachable from i in one move #outputs the label of the Grundy function g:=proc(G) local T,A,V,v,v1,i: #A: set of vertices already labelled #T the table of Grundy function values #L vertices already labelled V:={seq(i,i=1..nops(G))}: A:={}: for i from 1 to nops(G) do if G[i]={} then T[i]:=0: A:=A union {i}: fi: od: while A<>V do for v in (V minus A) do if G[v] minus A={} then T[v]:=mex({seq(T[v1],v1 in G[v])}): A:=A union {v}: next: fi: od: od: [seq(T[i],i=1..nops(G))]: end: g2:=proc(i,j) local k: option remember: mex({seq(g2(k,j),k=0..i-1),seq(g2(i,k),k=0..j-1)}): end: