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. Tastes Like Winning
  5. Discussions

Tastes Like Winning

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 11 Discussions, By:

votes

Please Login in order to post a comment

  • jananda
    4 years ago+ 1 comment

    please add another sample so we can understand this better. Could not undesrsatnd using one example.

    6|
    Permalink
  • kstauffer
    2 years ago+ 1 comment

    This challenge is poorly written. Here's a better explanation.

    In (this version of) the game of Nim, whoever takes the last stone wins. On your turn, you can take as many stones as you want from any single pile. You have to take at least one stone on your turn (you cannot pass). It is a well known result in game theory that if both players play optimally, then the winner is decided by the following property. On your turn let p be the number of piles, let size[i] be the number of stones currently in pile i. If size[1] XOR size[2] XOR size[3] ... XOR size[p] != 0, then it is possible for you to make a move that forces your opponent to lose (eventually). If that XOR is 0, then no matter what you do, the opponent (if they play optimally) can make a move that forces you to lose (eventually).

    This challenge wants the number of initial setups such that the first player can force a win, with one extra condition: at the start of the game no two piles have the same number of stones.

    So, you want to count the number of ways to take n distinct integers from [1, 2^m-1] such that the XOR of those n values is not zero.

    1|
    Permalink
  • alex_fotland
    1 year ago+ 0 comments

    I hate writing O(n) algorithms where n is an input value (rather than the memory size of the input); those are just exponential algorithms making a poor effort to pretend otherwise. But apparently it's good enough here.

    0|
    Permalink
  • louisaldorio
    2 years ago+ 0 comments

    I really dont get what the question want, any simpler explanation?

    0|
    Permalink
  • aditishrivastav4
    2 years ago+ 0 comments

    i didnt understood ques and messed up at last because output were different. how r they supposed to take stones ? i didnt got it till now... explain plz.​

    0|
    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