# Introduction to Nim Game

# Introduction to Nim Game

+ 3 comments Well, I remember NIM since reading Martin Gardner's book many years ago and even used it for nim playing bot simulation in uni, but since then forgot the idea, so when few years ago friend of mine asked me about it and I spent quite some time figuring it out myself, this time after long practicing on HR it was much easier. Just wondering what is the purpose of people sending here ready solutions and what's the use for others of just copying somebody else's code? You brain should work, that's the idea of all these challenges, not receiving badges for copy/paste

+ 0 comments A few hints for those having trouble.

If two piles have the same size, they can be disregarded: a player can keep his or her opponent in a "losing" state by taking as many stones from one pile as said opponent does the other.

The basic "losing" state is having zero piles in front of you. A derivative "losing" state is having two piles of 3 stones [3,3] for the reason described above.

If you can pair off every pile but one (say, two piles of 1 stone, one pile of 2 stones, and two piles of 3 stones [1,1,2,3,3]), you have won (as you can take the odd pile out and then force your opponent to lose).

No matter what you do, if you have a pile of 1 stone, a pile of 2 stones, and a pile of 3 stones in front of you [1,2,3], you've lost. This example is not as arbitrary as it sounds.

+ 0 comments The explanation of this problem is horribly confusing

+ 1 comment The solution is simply exoring all the pile sizes

If xor of all pile sizes is 0 then 2nd player wins

else 1st player

+ 1 comment https://www.youtube.com/watch?v=ORaGSyewF9Q , best explanation... :)

Sort 66 Discussions, By:

Please Login in order to post a comment