- 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!
+ 0 comments The task contains errors: both, the test case 2 and test case 3 contain subtests where k = 0. Accoeding to the conditions such cases must be excluded (1 <= n,k <= 100). I see again and again errors in provided test cases, hackerrank does not do proper check of tasks and tests,
Sort 38 Discussions, By:
Please Login in order to post a comment