Help := proc() if args = NULL then print(`Mex,NS`); print(`NimHeap,WK,WYTQ`); print(``); print(`Followed Winning Ways chapter 3`); print(`Mex = minimal excluded number`); print(`NS = Nim Sum , NimHeaps = Nim of general number of heaps`); print(`WK = White Knight, WYTQ = Wythoff Queen`); print(``); print(``); print(``); elif args = `Mex` then print(`Mex(S), input the set of integer S`); print(`return the smallest nonnegative integer that is not in S`); elif args = `NS` then print(`NS(a,b), input a,b the number of coin in heap1 and heap2`); print(`return the nim-value of this game`); elif args = `NimHeaps` then print(`NimHeaps(S), input set of integers which are the number of bean`); print(`in each pile`); print(`return the nim-value of this game`); elif args = `WK` then print(`WK(a,b), input the position of the knight on the chess board`); print(`The rule is you can move the knight downward or leftward or`); print(`pick the stone of the pile (start with many stones)`); print(`if you have to move th knight to (1,1),(1,2),(2,1) or (2,2)`); print(`then you lose`); print(`this function return the Grundy number of this game`); elif args = `WTYQ` then print(`WTYQ(a,b), input the position of the queen on the chess board`); print(`Two players take turn moving the queen toward (0,0)`); print(`the legal move is down or left or downleft`); print(`player who have to move to (0,0) lost`); print(`this function return the Grundy number of this game`); fi: end: Mex := proc(S) local A,i: A := sort([op(S)]); A := [op({op(A)})]; if A[1] < 0 then A := [op({op(A)} minus {seq(i,i = A[1]..-1)})]; fi: for i from 0 to nops(A)-1 do if A[i+1] <> i then return(i): fi: od: return(nops(A)); end: NS := proc(a,b) option remember: local i,x,y,sol: x := convert(a,base,2): y := convert(b,base,2): x := [op(x),0$(nops(y)-nops(x))]; y := [op(y),0$(nops(x)-nops(y))]; return(add( 2^(i-1)*(x[i]+y[i] mod 2), i = 1..nops(x))); end: NimHeaps := proc(S) option remember: local A,N,i,j: if nops(S) = 2 then return(NS(S[1],S[2])); fi: N:= []; A := sort([op(S)]); for i from 1 to nops(A) do for j from 1 to A[i]-1 do N := [op(N), NimHeap([op(1..i-1,A),j,op(i+1..nops(A),A)])]; od: N := [op(N), NimHeap([op(1..i-1,A),op(i+1..nops(A),A)])]; od: return(Mex(N)); end: WK := proc(a,b) option remember: if a < 0 or b < 0 then return(ERROR); fi: if a <= 2 and b <= 2 then return(0); fi: if a = 1 then return(Mex([WK(a+1,b-2)])); elif a = 2 then return(Mex([WK(a+1,b-2),WK(a-1,b-2)])); elif b = 1 then return(Mex([WK(a-2,b+1)])); elif b = 2 then return(Mex([WK(a-2,b+1),WK(a-2,b-1)])); else return(Mex([WK(a+1,b-2),WK(a-1,b-2),WK(a-2,b+1),WK(a-2,b-1)])); fi: end: WYTQ := proc(a,b) option remember: local i; if a <0 or b<0 then return(ERROR); fi: if a = 0 and b=0 then return(0); fi: return(Mex([seq(WYTQ(i,b),i=0..a-1),seq(WYTQ(a,i),i=0..b-1), seq(WYTQ(a-i,b-i),i=1..min(a,b))])); end: