Nim-Value

Author

Eric W. Weisstein
October 19, 2003

This notebook downloaded from http://mathworld.wolfram.com/notebooks/Games/Nim-Value.nb.

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

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

Initialization

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

2 Heaps

Select[Flatten[Outer[List,Sequence@@Table[Range[10],{2}]],1],NimValue[Sequence@@#]==0&]

3 Heaps

Select[Flatten[Outer[List,Sequence@@Table[Range[7],{3}]],2],NimValue[Sequence@@#]==0&]

Union[Sort/@%]

4 Heaps

safe4=Union[Sort/@Select[Flatten[Outer[List,Sequence@@Table[Range[7],{4}]],3],NimValue[Sequence@@#]==0&]]

DeleteCases[safe4,{x_,x_,y_,y_}]