Sort by

recency

|

18 Discussions

|

  • + 0 comments

    Dive into the complexities of "Unfair Game" with our promotional notepads. Ideal for noting down critical insights, strategies, and reflections, these notepads help you stay organized and focused. Whether analyzing game mechanics, documenting unfair play tactics, or brainstorming solutions, our notepads ensure you capture every detail. Stay ahead of the game and make informed decisions with our practical and stylish promotional notepads, designed for those who navigate the intricate world of "Unfair Game."

  • + 1 comment

    It took days for me to understand the DP solution by reading other solutions and comments and this link https://plus.maths.org/content/play-win-nim. I know this is an old problem but I feel like writing an editorial based on what I know since there isn't one.

    First read the link above. With that we can reduce the problem to: what is the minimum number of stones to add to make the XOR of the piles equal to 0? Though, this problem is still very difficult.

    Since we are dealing with XOR, it is useful to think in terms of bits. Assume the optimal solution adds to for all . What happens to the bits when we add them both? Notice that the highest bit that changes in always goes from to otherwise the result would be less than which is not possible since is positive. Let be the position of that bit . We can break into parts such that :

    • the minimum to add to make the bit and all lower bits
    • for turning on the bits after adding to make it all sum back to

    There are s that we don't know. Here's where DP comes in.

    Let's go from highest to lowest bit and set for some s where is the current bit position. This suggests a bitmask approach where the bit is on in the mask if .

    Let be the minimum to add only considering XOR of the bits and above such that represents the : . The transition from to looks like a variation of the "sum-over-subsets DP" however I could not find an solution using this method. The trick is that we do not need to consider all submasks. Say that we have , such that . Since turns all 's bits lower than into zeroes, we may use to change parity as needed. Since the goal is to make the number of ones at the current bit position even, we only set at most once, right? This is only true for that are not the maximum. If there is no , such that there would be no way to change parity unless we set another , . This means there can be at most 2 maximum s. With this the transition from to can be done in thus the total time is .

    Let be the position of the lowest bit such that for all .

    Base cases:

    • : nothing to add when all bits and above are zero.
    • for all non-empty s: no need to consider the rest; mask starts empty.

    DP transitions:

    • for all such that the number of on bits not in the is odd.
    • for all and the bit in is off and the number of on bits not in the is odd.
    • for all such that the number of on bits not in the is even.
    • for all such that the parity of the number of elements in the is the same as the parity of the number of on bits not in the and the number of elements in the mask is at most 2 and there are no on bits in the .

    Answer:

    : we may end with any mask.

  • + 0 comments

    Here is my solution in java, javascript, python, C, C++, Csharp HackerRank Unfair Game Problem Solution

  • + 0 comments

    Here is Unfair Game problem solution in Python Java C++ and C programming - https://programs.programmingoneonone.com/2021/07/hackerrank-unfair-game-problem-solution.html

  • + 0 comments

    The game is simple, all you have to do is make the xor of all the piles equal to zero if they are not already. The main thing is finding the algorithm for this.

    Look at the the bitwise xor of all the elements

    For example: piles = [10,4,5,1]

    if I draw its bitwise map then (Symbol "x" equates to 1) :

    10  = > X 0 X 0
    4   = > 0 X 0 0
    5   = > 0 X 0 X
    1   = > 0 0 0 X
    

    Now make their xor equal to zero and using the minimum amount of changes. From here all you need to do is check if there is an requirement of 1 or there is excess of 1 and we need to look column wise for this to solve. If there is excess of 1 then find the row which has the nearest 1 and then shift it's position. If it is excess then you need to shift the excess in front and start with that row.

    (Initial)

    10  = > X 0 X 0
    4   = > 0 X 0 0
    5   = > 0 X 0 X
    1   = > 0 0 0 X
    

    (Step - 1) (We correct for row 1)

    10  = > X 0 X 0
    8   = > X 0 0 0
    5   = > 0 X 0 X
    1   = > 0 0 0 X
    

    (Step - 2)(We correct for row 2)

    12  = > X X 0 0
    8   = > X 0 0 0
    5   = > 0 X 0 X
    1   = > 0 0 0 X
    

    (Step - 3) and (Step - 4) are not necessary to show as they are already corrected.

    Let's take another example for the case of piles = [1,1,1]

    (Initial)

    1 = > 0 X
    1 = > 0 X
    1 = > 0 X
    

    (Step - 1) In this there is an excess of 1 so we shift that one ahead and start with that row again

    1 = > 0 X
    1 = > 0 X
    2 = > X 0
    

    (Step - 2) Now, we need to apply correction to the row that we just shifted.

    1 = > 0 X
    2 = > X 0
    2 = > X 0
    

    (Step - 3) Now first row has been corrected and the second row needs correction. If there is no other way to add an 1 the we introduce the 1 in the last row

    1 = > 0 X
    3 = > X X
    2 = > X 0
    

    Now, you just need to convert the rows to their respective integers and subtract and add the difference in the count and return the count

    For example:

    piles   = [1,1,1]
    ^piles  = [2,3,1]
    total   =  1 + 2 + 0 = > 3
    

    and

    piles   = [10,4,5,1]
    ^piles  = [12,8,5,1]
    total   = 2 + 4 + 0 + 0 = > 6
    

    and

    piles   = [1,3]
    ^piles  = [3,3]
    total   = 2 + 0 = > 2
    

    That is how to solve this question I guess. I will try it.