#Tim Naumovitz's Maple code for Chomp that won him the third prize in the Final Experimental Math Contest
#Sprague Grundy function for chomp
#The sprague grundy function for an M by N
#rectangle game of chomp
G:=proc(M,N) local L,i:
L:=[M$N]:
Ggen(L):
end:
#The set of moves that can be made in a
#game of chomp from this position, representing
#the game as a list of integers where L[1] is
#the length of row i
Moves:=proc(L) local i,j,M,L1,k,L2:
M:={}:
for i from 1 to nops(L) do
for j from 1 to L[i] do
L1:=L:
for k from i to nops(L) do
if L1[k]>j-1 then
L1[k]:=j-1:
fi:
od:
if j=1 then
L2:=[op(1..i-1,L1)]:
L1:=L2:
fi:
M:=M union {L1}:
od:
od:
M minus {[]}:
end:
#The Sprague-Grundy function for a
#game of chomp in position L
Ggen:=proc(L) local i,L1:
option remember:
if L=[1] then
RETURN(0):
fi:
L1:={}:
for i in Moves(L) do
L1:=L1 union {Ggen(i)}:
od:
Mex(L1):
end:
#The Mex function (minimum excluded element)
Mex:=proc(L) local i:
for i from 0 to nops(L) while i in L do od:
i:
end: