Marienbad

Author

Eric W. Weisstein
April 30, 2002

This notebook downloaded from http://mathworld.wolfram.com/notebooks/Games/Marienbad.nb.

For more information, see Eric's MathWorld entry http://mathworld.wolfram.com/Marienbad.html.

©2005 Wolfram Research, Inc. except for portions noted otherwise

Nim-Value

NimValue[n__]:=Module[{len=Length[IntegerDigits[Max[n],2]]},
FromDigits[Mod[Plus@@(IntegerDigits[#,2,len]&/@{n}),2],2]
]

NimValue[1,3,5,7]

Ergo, player 1 will always win if he plays correctly.

Graphic of Nim-Heap

Counter[n_,y_]:=Module[{dx=.1,h=.2,dy=.05},
Rectangle[{n+dx,(y-1)(dy+h)},{n+1-dx,(y-1) (h+dy)+h}]
]

NimHeap[l__]:=Counter@@@Flatten[MapIndexed[Outer[List,#2,#1]&,Range/@{l}],2]

Show[Graphics[NimHeap[1,3,5,7],AspectRatio->Automatic]]