#Tim Naumovitz #Homework for Monday, Feb 4 #I give permission to post this #Problem 2 #If f(m,n) is the Sprague-Grundy function for two-pile Nim, then #f(2m,2n)=2f(m,n), f(2m+1,2n)=2f(m,n)+1, f(2m,2n+1)=2f(m,n)+1, #f(2m+1,2n+1)=2f(m,n) #Proof: Follows from Lemma 1 #Lemma 1: f(m,n)=m+n, where + represents bitwise xor. #Proof: induction on m,n #Base Case: f(0,0)=0+0=0 #Induction Step: #Let S be such that f(m,n)=mex(S). #Let r=m+n, and let i be the index of the most significant bit of r #(indexing starts with the least significant bits). Let s=y>0, m=x+y. By the inductive hypothesis, #f(x,n)=x+n=(m-y)+n. Since m-y <> m, m and m-y differ in some #bit h. This means (m-y)+n and m+n=r differ in some bit h, so #f(x,n)<>r. This gives us that r is not in S, and s is in S for s0 for any Q #reachable from P. By the inductive hypothesis, f(Q) is a Winning #position. This means that f(P) is a Losing position, since every #position reachable from P is Winning. # #Now assume that P is a Losing position. This means that every position Q #reachable from P is a Winning position, so f(Q)<>0. By the mex #definition of f, f(P)=0. #SGwyt(i,j): inputs two non-negative integers i and j and outputs the #Sprague-Grundy function of position (i,j) in Wythoff's game, where a #legal move consists of taking a positive number of pennies from either #pile, or the same number from both. SGwyt:=proc(i,j) local k: option remember: mex({ seq(SGwyt(i-k,j),k=1..i), seq(SGwyt(i-k,j-k),k=1..i), seq(SGwyt(i,j-k),k=1..j)}): end: #WinningMove(G,i): inputs a game given as a digraph G, and a position i #(between 1 and nops(G)), and outputs a winning move (a member of G[i]) if #one exists, or FAIL if i is a losing (alias P) position. WinningMove:=proc(G,i) local k: if SG(G,i)=0 then RETURN(FAIL): fi: for k in G[i] do if SG(G,k)=0 then RETURN(k): fi: od: end: