- Prepare
- Algorithms
- Game Theory
- Poker Nim
- Discussions

# Poker Nim

# Poker Nim

+ 3 comments Same as regular game of Nim!

Some insight: being able to add to the pile makes no difference to a regular game of nim. If Player A has a winning position in the game of nim, Player A may keep playing optimally as they would play a regular nim game. If, however, Player B decides to add k items to a pile, putting Player A in a losing position, Player A may add the same number, k, items to the same pile, reclaiming thier winning position. Or, even better, Player A may simply remove the items added by Player B.

+ 1 comment def pokerNim(k, c): res=0 for i in c: res^=i if(res): return("First") else: return("Second")

+ 0 comments Really, really poorly worded question, doesn't describe the way it's supposed to run at all (at least for the Javascript version of the question.)

+ 0 comments # General Solution Tips

- The modifications to a regular game of Nim described in the problem have no impact on the outcome.
- The problem statement boils down to:

Given the list of Nim heaps, will player 1 or player 2 win?

- This problem is easily solved by implementing XOR
- "Nim" game solutions are well documented: check out https://en.wikipedia.org/wiki/Nim#Proof_of_the_winning_formula

I hope that helps!

+ 1 comment Hi,

Here's my math behind the problem. I am not able to understand why is it wrong.

A is first. B is second. Initially let say the total no. of chips to be T. If T is even After a full move(i.e. A and B both move provided game has not ended) the total no. of chips would still remain even. And same reasoning goes for the odd case.

Now if addition was not allowed T would have determined who is winner. If T were odd A would else B would.

Now even though addition is allowed but after a move the total no. of elements stay in same state. i.e. if T = even, then after each move the total chips would still be even. and vice versa. Hence win is also decided by the same as above. So even though addition is allowed still the factor of 'k'(the total no. of addition available for each pile) is not doing anything to the problem.

So where is the factor k playing role here ? what was the need of i piles when all of this is can be done using single pile ? And where is my math going wrong ??? Have I not understood the Q correctly ?

Heres how I understood the Q.- There are 2 players A and B. There are i piles. In each pile eachof the players can add maximum of k tokens. They can add even though the ith pile is finished. Now both are playing selfishly. Who will win if A starts

Sort 37 Discussions, By:

Please Login in order to post a comment