Sharky and Ivan are playing a strange game, with Sharky going first.
They start with a heap of 420 coins. They then take turns to remove some of the coins using the two rules below.
Given that the number of coins in the pile is k , you may either
If a person cannot make a legal move, they lose. Who has the winning strategy?
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
And (as is often the case in games like this) there is no "strategy"--the winner is predetermined no matter how the players play.
Log in to reply
In most of the games (including these), then yeah. Not all, fortunately.
Wow... Great solution!
Though I had solved it, but as soon as saw that "Sharky" gave the question, I knew that "Sharky" must be having the winning strategy
Playing the game reveals that:
The first player wins when the starting number of coins is 2 , 3 , 5 , 8 , 9 , 1 2 , 1 4 , 1 5 , . . .
The first player loses when the starting number of coins is 1 , 4 , 6 , 7 , 1 0 , 1 1 , 1 3 , 1 6 , . . .
which one may recognize as the beautiful Thue-Morse sequence!! where a 1 appears at index n if the first player wins when given n coins, and a 0 appears otherwise.
[The Thue-Morse sequence is computed by starting with an initial 0 , and repeatedly appends the negation of the already-found sequence, i.e., [ 0 ] [ 1 ] [ 1 0 ] [ 1 0 0 1 ] [ 1 0 0 1 0 1 1 0 ] [ 1 0 0 1 0 1 1 0 0 1 1 0 1 0 0 1 ] , etc.]
The Thue-Morse sequence has many interesting properties, which makes this connection so amazing; examples are that any substring is not repeated more than twice in a row and that it can be neatly applied to the fair-sharing problem and the equal-sums-of-powers problem. But the property that allows us to finish the problem is that there is an explicit formula for each digit of the sequence: the digit at index n is equal to the number, modulo 2 , of ones in the binary representation of n − 1 .
Since 4 2 0 − 1 = 4 1 9 = 1 1 0 1 0 0 0 1 1 2 has 5 ones in its binary representation, the 4 2 0 th digit of the Thue-Morse sequence is a 1 , and therefore the first player (Sharky) wins when starting with 4 2 0 coins.
Great question with an even greater solution!!!
This question "who has the winning strategy?" makes no sense! You only declared rules of the game, and who goes first... it would be really helpful to re-phrase this problem.
Log in to reply
"Who has the winning strategy?" means to ask who will be the winner if they chose to play optimally. This is standard in most questions of this type.
Log in to reply
The language is typical, but in this case Sharky doesn't have a losing strategy. There are exactly five legal moves of two types. The game will end after five moves regardless of what Sharky decides to do.
Oh... i misunderstood the prob. In operation 1, if 2^n < k, with n being largest possible... i thought that n has to be removed.. not 2^n . Thanks..
This shouldn't be a Level-1 question..!!
Log in to reply
It was a level 4, but as you see, it became the "Problem of the Week" so people start solving them (about 4000 solvers and counting) That's simply why this is a level 1.
The names should be changed by the way. I think a lot guessed the answer as Sharky ;)
Great solution SHARKY!!!! But why did you made the character lose who has been named after you!!! Ha ha ha
The trick is to immediately convert 420 into binary 110100100. The two rules then become
Remove the left-most 1 (and any 0s between that and the next 1)
Remove the right-most 0
Whichever order the players choose to do these steps, it will take exactly five steps to reduce the number to a single 1.
Please let me know if there are mistakes in my reasoning:
For me, I see 420 = 2^8 + 2^7 + 2^5 + 2^2
Operation 1 is equivalent to removing the 1st term (the left most one). Operation 2 is equivalent to reducing the powers of every term by one.
The game comes to an end when a player is left with exactly one coin, which is the only situation where no legal moves are possible.
Operations 1 or 2 may be carried out in any order, but operation 2 will be executed exactly *twice * (need not be consecutively), after which the last term ends up becoming 1, making the sum to be odd and therefore making it impossible to perform operation 2 according to its rule. As for operation 1, it will be executed exactly 3 times , after which there will only be 1 term left.
Hence, after exactly 5 moves (3 times of op. 1 and 2 times of op. 2 regardless of order), only 1 coin will be left. The player who has to make the 6th move will not have a legal move and will therefore lose the game. Since 6 is an even number, the one who makes the first move will win. Congratulations, Sharky!
A perfectly right and beautifull solution! As far as I understand, the logic of your solution is the same as that of Sharky Kesa's solution, presented in a different and interesting way
Log in to reply
Thank you! Yes, the underlying logic is the same, just that I did not use binary expressions.
This is really lovely solution! Thanks for sharing
Awesome...Awesome...Awesome... don't doubt your reasoning. This is the best explanation to this question.
Not such an elegant, general solution, but all roads seem to lead rapidly to a Sharky win!!
Step 0....S .....................420
Step 1....I.............164 .......or........ 210
Step 3...S......... 26...or..........82....or....105
Step 3...I .........13...or...10,......18...or....41
Step 4...S.............5......or....2.......or .... 9
Step 5....I ...........................1!!!!
It is a good solution
Log in to reply
The 26 messes things up. There's no path to getting to 26, 13, 10, or 5 if you start with 420 coins.
Its a good solution..but a small correction: 164-128 = 36 not 26
I worked on the solution the same way that you did but I got Ivan has more winning paths. Am I missing something here?
One huge flaw in the solution. Either one of them could win. It says one can take half the coins if there is an even number. Sharky can take 210; Ivan can take the other 210 and win.
Log in to reply
Wrong. When it's Ivan's turn, he is facing 210 coins, so he can either take 105 or 128 coins, not the whole thing.
There is no winning "strategy" in a sense-- no matter what choices the player makes, Ivan will lose at his third turn.
Let N be the number of coins in the heap, and resolve it in the form N = k ∈ S ∑ 2 k , where S is a set of non-zero integers. In this case, N = 4 2 0 = 2 8 + 2 7 + 2 5 + 2 2 so that S = { 8 , 7 , 5 , 2 } .
Let's consider the effect of each valid moves on the set S : they are
remove the largest value from S , provided ∣ S ∣ > 1 ;
subtract one from each element of S , provided 0 ∈ S .
The first operation will decrease ∣ S ∣ (the number of elements in S ) by one but not affect min S ; the second operation will decrease min S by one, but not affect ∣ S ∣ . Therefore the characteristic value c = ∣ S ∣ + min S will decrease by one in every turn. Moreover, a player can only lose if both ∣ S ∣ = 1 and 0 ∈ S , i.e. when c = 1 . Therefore, given an initial situation with characteristic c , we know that there are c − 1 moves before the game ends.
In this situation, c = 4 + 2 , so that there are 5 possible moves before Ivan loses.
This is no match for Sharky's lovely solution of the general case, but more modestly solves the game from the specified starting point.
We can start with three observations and then show that Sharky has a winning strategy.
First note that if there is one coin in the pile there is no legal move.
Next note that if the pile has more than one coin there will be a legal move.
These two observations together show that the loser will be the first person confronted with a pile containing one coin.
Finally note that once there is an odd number of coins in the pile, the number of coins remains odd for the rest of the game. This is because move-option 2 is not permissible and move-option 1 involves subtracting an even power of 2. An odd number minus an even number always produces another odd number. So once there is an odd number of coins in the pile, the moves of both players are forced to be move-option 1.
Now here is Sharky's strategy. He should half the number of coins leaving 210 coins. Now if Ivan halves the number to leave 105 in the pile we are onto an odd number chain and there are no more choices to be made. The sequence goes
420-210-105-41-9-1
If instead of halving the 210, Ivan takes away 128 coins, Sharky should halve the result which switches the game onto the odd number track. The sequence now goes
420-210-82-41-9-1
Both of these sequences have five moves, so the next move is Ivan's. But since he is confronted with a pile of one coin he has no legitimate move and so looses the game.
Not that we really need another solution, but the 3 by 4 grid below shows all the possible states:
420 & 164 & 36 & 4
210 & 82 & 18 & 2
105 & 41 & 9 & 1
At any state there are two possible moves: to the right or down. Subtracting the largest power of two is a move to the right. Dividing by two is a move down. These moves commute with each other, i.e. subtracting the largest power of two followed by a division by two leads one to the same point as doing the same operations in the opposite order. Of course if I listed all the numbers by their binary representation, the nature of the grid would be more obvious.
110100100 & 10100100 & 100100 & 100
11010010 & 1010010 & 10010 & 10
1101001 & 101001 & 1001 & 1
The move to the right is accomplished by removing the leading '1' while the move down is accomplished by removing the last '0'.
I got it right with what i could understand, but want to make sure i understood correct,
Given k = 420, largest power of 2 < k = 2^8 = 256
Am left with 2 questions, what is a winning strategy here? And why Sharky is on Winning Strategy?
Firstly, Ivan can't remove 4 coins, because it isn't the largest power of 2 less than k (instead, it is equal to k ). Secondly, winning strategy means, who is the winner given both play optimally.
For a person to lose, they must either end with a odd number
We immediately notice that removing a power of 2 does not "remove a two", that is, cause the number to lose a power of two. We also notice
420=2^2 3 5*7
thus, Sharky will always have the upper hand by forcing Ivan to have a odd number.
Problem Loading...
Note Loading...
Set Loading...
Reading the question, we find that this is a game. Obviously, the first thing everyone solving this should do is to
Play the game!
Let's try a few smaller values and see what we get. (The first column represents the player who has just taken coins, and n represents the number of coins in the pile)
Player Start Sharky Ivan Sharky Operation 1 2 1 n 2 2 6 3 1
Notice that Ivan can't play any operation on 1 since it is both a power of 2 and odd. We observe that the winner will make n = 1 . Thus, Sharky won if Ivan had used the first operation. Let's see what happens if Ivan had used the other operation.
Player Start Sharky Ivan Sharky Operation 1 1 2 n 2 2 6 2 1
So it seems Sharky has the winning strategy for 22. Let's try more numbers!
Player Start Sharky Ivan Sharky Ivan Operation 1 2 2 1 n 2 8 1 2 6 3 1
In this case, it seems Ivan won. Using our previous game, we know 6 is a losing position for the person who's about to remove coins from it. Thus, we don't need to investigate Sharky's second move. What about his first move though?
Player Start Sharky Ivan Sharky Ivan Operation 2 1 2 1 n 2 8 1 4 6 3 1
Here, we find almost the same position yet again! Thus, we know Ivan has a winning strategy for 28.
If you keep playing this for different values of n , you might observe some sort of pattern. However, how would you prove it? Think about this, then keep reading down to find out a great strategy for solving this.
If you were thinking about converting n to binary, you are correct in thinking so. Motivation for thinking about this is because you are either subtracting the greatest power of 2 from it, which translates in binary to removing the first digit 1 (if there exist other non-zero digits), or halving it, which translates in binary to removing the last digit 0 (if it exists). These both feel like easy operations to deal with. Let's analyse the above games with a conversion to binary to see what's happening.
Player Start Sharky Ivan Sharky Operation 1 2 1 n 2 2 6 3 1 n 2 1 0 1 1 0 1 1 0 1 1 1
Player Start Sharky Ivan Sharky Operation 1 2 1 n 2 2 6 2 1 n 2 1 0 1 1 0 1 1 0 1 0 1
Player Start Sharky Ivan Sharky Ivan Operation 1 2 2 1 n 2 8 1 2 6 3 1 n 2 1 1 1 0 0 1 1 0 0 1 1 0 1 1 1
Player Start Sharky Ivan Sharky Ivan Operation 1 2 2 1 n 2 8 1 4 6 3 1 n 2 1 1 1 0 0 1 1 1 0 1 1 0 1 1 1
From here, we can see that the first operation can only be applied a − 1 times, where a signifies the number of 1's in the binary representation of n , and also that the second operation can be applied b times, where b signifies the number of terminating 0's in the binary representation of n .
Observe that after each move, the sum a + b decreases by 1. Thus, after both Sharky and Ivan have their turns, a + b decreases by 2. Therefore, we must have a + b constant in ( m o d 2 ) after Sharky and Ivan have made their moves. This simplifies the problem dramatically. We also note from previously that if n = 1 , then the next player loses.
If a + b is odd, then we must have a + b ≡ 1 ( m o d 2 ) . After Sharky and Ivan keep making their moves, eventually, Ivan will have made n to be equal to 1. Thus, Ivan wins if a + b is odd. Similarly, if a + b is even, Sharky wins.
We have solved the general case!
To solve for n = 4 2 0 , we note n 2 = 1 1 0 1 0 0 1 0 0 , which has a = 4 and b = 2 , so a + b is even. Thus, Sharky is the winner.