We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Game Theory
  4. Poker Nim
  5. Discussions

Poker Nim

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 38 Discussions, By:

votes

Please Login in order to post a comment

  • zaleyoung
    5 years ago+ 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.

    14|
    Permalink
  • ajinkyaomble17
    2 years ago+ 1 comment
    def pokerNim(k, c):
        res=0
        for i in c:
            res^=i
        if(res):
            return("First")
        else:
            return("Second")
    
    12|
    Permalink
  • joe_busuttil
    3 years ago+ 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.)

    9|
    Permalink
  • driftwood
    3 years ago+ 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!

    5|
    Permalink
  • andrush_alex
    2 years ago+ 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,

    1|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature