#Patrick Devlin's Maple Code for Chomp that won him the first prize at the Experimental Math Final Contest #on May 6, 2013 (done in less than 20 minutes!) # Input is a non-increasing list [l1, l2, ..., lk] of non-negative numbers indicating that there are # lj guys in row j. chomp:=proc(L) local i, j, possibleMoves; option remember: if(nops(L)=1) then if(L[1]=1) then return 0: fi: fi: possibleMoves:={}: for j from 1 to (L[1]-1) do possibleMoves:=possibleMoves union {chomp(nibble(L,1,j))}: od: for i from 2 to nops(L) do for j from 0 to (L[i]-1) do possibleMoves:=possibleMoves union {chomp(nibble(L,i,j))}: od: od: return mex(possibleMoves): end proc: nibble:=proc(L,i,j) local newL,k: if(i>nops(L)) then print(`FAIL 1 in nibble`); return L: fi: if(j>L[i]) then print(`FAIL 2 in nibble`); return L: fi: newL:=[seq(L[k], k=1..(i-1))]: for k from i to nops(L) do if(min({j,L[k]}) >0) then newL:=[op(newL), min({j,L[k]})]: fi: od: return newL: end proc: mex:=proc(S): return min( {seq(i,i=0..(nops(S)+3))} minus S): end proc: G:=proc(M,N) local i,j,k: return([seq([seq(chomp([seq(i,k=1..j)]),j=1..M)],i=1..N)]): end proc: