Two players are playing a game. They start by flipping 7 fair coins and arranging them randomly in a row. On a player's turn, she may flip over one coin from heads to tails, or flip over two adjacent coins which show heads to tails. A player loses if there are only tails remaining and it is now her turn to make a move. For how many of the 2 7 = 1 2 8 possible positions of the coins does the first player win?
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.
I'd be interested to solve this problem generally. I was going to say that for any losing state, adding 3 coins to one pile produces another losing state, but actually this isn't true: { 2 , 5 } is a winning state as it can be reduced to { 2 , 1 , 3 } , which is the smallest possible three-pile losing state. It seems that the pattern gets more complicated beyond N = 7 :)
Log in to reply
My argument will work for larger N - you just need to calculate more than g ( 0 ) , g ( 1 ) , … , g ( 7 ) .
Log in to reply
On a little looking, I find that this game is completely analysed. It is the octal game 0 . 7 7 , called Kayles. The value of g ( n ) is known for all n ≥ 0 , being eventually periodic of period 1 2 .
How did you become sure that the list of losing states which you provided contains all of the losing states???
Log in to reply
Because I wrote down all the possible states; and all the states which have a winning move went into the "Winning" category, and what's left went into "Losing".
"Losing" got started off with all the states that can be divided into two equal groups, i.e. 0, {1,1}, {2,2}, {3,3}, {1,1,1,1}.
Reading the discussion about the Sprague-Grundy function will be useful.
This is a Nim-type game, where the stacks on the Nim board are the sizes of the consecutive strings of heads. At each go, the player can remove one or two heads from one of the strings, which may divide the string into two pieces. The Grundy function for this game is g ( 0 ) g ( 1 ) g ( 2 ) g ( 3 ) g ( 4 ) g ( 5 ) g ( 6 ) g ( 7 ) = = = = = = = = = = = = = 0 m e x { g ( 0 ) } = 1 m e x { g ( 0 ) , g ( 1 ) } = 2 m e x { g ( 1 ) , g ( 2 ) , g ( 1 ) ⊕ g ( 1 ) } m e x { 1 , 2 , 0 } = 3 m e x { g ( 2 ) , g ( 3 ) , g ( 1 ) ⊕ g ( 2 ) , g ( 1 ) ⊕ g ( 1 ) } m e x { 2 , 3 , 3 , 0 } = 1 m e x { g ( 3 ) , g ( 4 ) , g ( 1 ) ⊕ g ( 3 ) , g ( 2 ) ⊕ g ( 2 ) , g ( 1 ) ⊕ g ( 2 ) } m e x { 3 , 1 , 2 , 0 , 3 } = 4 m e x { g ( 4 ) , g ( 5 ) , g ( 1 ) ⊕ g ( 4 ) , g ( 2 ) ⊕ g ( 3 ) , g ( 1 ) ⊕ g ( 3 ) , g ( 2 ) ⊕ g ( 2 ) } m e x { 1 , 4 , 0 , 1 , 2 , 0 } = 3 m e x { g ( 5 ) , g ( 6 ) , g ( 1 ) ⊕ g ( 5 ) , g ( 2 ) ⊕ g ( 4 ) , g ( 3 ) ⊕ g ( 3 ) , g ( 1 ) ⊕ g ( 4 ) , g ( 2 ) ⊕ g ( 3 ) } m e x { 4 , 3 , 5 , 3 , 0 , 0 , 1 } = 2 We need to calculate the Nim score for each starting position of the board, and count the number of losing positions for the first player.
If there are 7 tails, then the first player loses. This gives us a count of 1 losing position.
If there are 6 tails, then there is just one head, so the Nim score of the board is g ( 1 ) = 1 . This is a winning position for the first player.
If there are 5 tails, we could have one sequence of 2 heads, or two sequences of 1 head. Since g ( 2 ) = 2 and g ( 1 ) ⊕ g ( 1 ) = 0 , the losing positions for the first player are the ones with two sequences of 1 head. There are 6 C 2 = 1 5 such positions.
If there are 4 tails we could have one sequence of 3 heads, a sequence of 2 heads and a sequence of 1 head, or else three sequences of 1 head. Since g ( 3 ) = 3 , g ( 2 ) ⊕ g ( 1 ) = 3 and g ( 1 ) ⊕ g ( 1 ) ⊕ g ( 1 ) = 1 , these are all winning positions for the first player, and so we get no more losing positions.
If there are 3 tails then since g ( 4 ) = 1 , g ( 3 ) ⊕ g ( 1 ) = 2 , g ( 2 ) ⊕ g ( 2 ) = 0 , g ( 2 ) ⊕ g ( 1 ) ⊕ g ( 1 ) = 2 and g ( 1 ) ⊕ g ( 1 ) ⊕ g ( 1 ) ⊕ g ( 1 ) = 0 , the losing positions for the first player are the ones where there are two sequences of 2 heads, or where there are four sequence of 1 head each. There are 4 C 2 = 6 for the first type, and 1 of the second type. This adds another 7 to our tally.
If there are two tails, then since g ( 5 ) = 4 , g ( 4 ) ⊕ g ( 1 ) = 0 , g ( 3 ) ⊕ g ( 2 ) = 1 , g ( 3 ) ⊕ g ( 1 ) ⊕ g ( 1 ) = 3 , g ( 2 ) ⊕ g ( 2 ) ⊕ g ( 1 ) = 1 , the only losing positions for the first player are when there is one sequence with 4 heads and one sequence with 1 head. There are 6 such boards.
If there is just one tail, then since g ( 6 ) = 3 , g ( 1 ) ⊕ g ( 5 ) = 5 , g ( 2 ) ⊕ g ( 4 ) = 3 , g ( 3 ) ⊕ g ( 3 ) = 0 , the only losing positions for the first player are those where there are two sequences of 3 heads. There is just one such board.
If there are no tails then, since g ( 7 ) = 2 , this is a winning position for the first player.
Thus there are 1 + 1 5 + 7 + 6 + 1 = 3 0 losing boards for the first player, and hence 9 8 winning boards.
Indeed, Sprague-Grundy motivates how to approach this question by 'deconstruction'.
However, each case of n coins will need to be separately done.
Log in to reply
Obviously. But since the function g is known for all n , working out the possibilities for any particular value of n is now a comparatively simple mechanical process.
In any particular arrangement, suppose we remove some tails between two heads maintaining the following restrictions:
i)
If there were a positive number of tails between two heads, after the transformation, there exists exactly
1
tail between two heads.
ii)
If there were no tails between two heads, after the transformation, there are still no tails between two heads.
Then, note that the state (winning or losing) of the transformed arrangement must be identical to the state of the original arrangement: it is obvious that the number of tails between two heads doesn't matter. All what matters is whether two heads are consecutive or not. Also, note that the number of coins of the transformed arrangement must be ≤ the number of coins in the original arrangement.
We call this transformation the reduced arrangement of the original arrangement. Note that the ends of the reduced arrangement of any arrangement must be heads.
Next, suppose in some arrangement we consider each block of few consecutive heads as a single block, and we permute these single blocks in such a way that no two blocks appear consecutive. We call two such arrangements friends of each other. As an explicit example, the arrangements H H T H and H T H H are friends of each other. Note that the states of two friends must be identical: we can consider the game as a combination of those blocks, the order obviously doesn't matter.
Now, note that to the end of any reduced arrangement if we append a
H
, the resultant arrangement will be winning iff atleast one of the following conditions are satisfied:
i)
The original reduced arrangement is losing.
ii))
If we remove the last head from the original arrangement, the resultant is a losing arrangement.
Also note that to the end of any winning arrangement if we append a
T
H
, the resultant arrangement in losing, and to the end of any losing arrangement if we append a
T
H
, the resultant will be winning.
The proof of the sufficient condition is trivial: if either one of the conditions hold, the first player has a move which pushes the second player to a losing position. If none of the conditions hold, the first player has no move that pushes the second player to a losing position, so he makes a move within the original arrangement, which is winning. The second player then flips the last head, and now the first player is in a losing position. This establishes our claim. The same proof holds for the latter claim.
Note that
H
and
H
H
are both winning positions, whereas
H
T
H
is a losing position. Starting from these three positions, we keep on appending
H
s keeping in mind our above algorithm. This generates the following losing reduced arrangements (note: in the following list we ignore two arrangements which are friends of each other, and the sum of the number of
H
s and
T
s is at most
7
).
H
T
H
,
H
H
H
,
H
H
H
H
T
H
,
H
T
H
T
H
T
H
H
T
H
T
H
H
H
,
H
H
H
H
H
H
,
H
H
H
H
H
T
H
H
H
H
T
H
H
H
Note that if any reduced arrangement has f friends and can be arranged in t ways in a 7 coin game, then that reduced arrangement will actually contribute t f losing arrangements. We compute t and f individually for each reduced arrangement. I am not showing it for each of the arrangements individually, but I am just giving a sketch. Take the arrangement H H H H H T H . To find its number of friends, consider the block H H H H H as a single block X , and the block H as another block Y . This has two permutations (note: X Y cannot be consecutive): X T Y and Y T X , so this reduced arrangement has two friends. To find the number of possibilities each friend of this reduced arrangement has, say there are a + 1 T s in place of the T , b T s before the first H , and c T s after the last *H), where a , b , c are non-negative integers. The equation is then a + b + c + 1 = 1 ⟹ a + b + c = 0 . We can find its number of solutions by the ball and bars method. Below we tabulate the analysis of each the reduced arrangements.
Arrangement #Friends #Total arrangements for each friend H T H ∣ 1 ∣ ∣ ( 4 6 ) = 1 5 H H H ∣ 1 ∣ ( 4 5 ) = 5 H T H T H T H ∣ 1 ∣ ∣ ( 3 3 ) = 1 H T H H T H H ∣ 2 ∣ ∣ 1 H H H H T H ∣ 2 ∣ 3 H H H H H H H ∣ 2 ∣ 1 H H H H H T H ∣ 2 ∣ 1 H H H T H H H ∣ 1 ∣ 1 Adding these, we get 3 0 losing positions, so the number of winning positions is 1 2 8 − 3 0 = 9 8 .
Problem Loading...
Note Loading...
Set Loading...
I am characterizing each starting position by the number of "piles", where a pile is a group of adjacent heads. For example the state { 2 , 3 } means the positions HHTTHHH, HHTHHHT, HHHTTHH, HHHTHHT, THHTHHH, THHHTHH.
There's two stages to the solution: deciding which states are winning, and then counting how many positions in total make up the winning states.
Here are the possible states divided into winning and losing ones (I'll justify this in a moment).
Losing: { 0 } , { 1 , 1 } { 2 , 2 } { 3 , 3 } { 1 , 4 } { 1 , 1 , 1 , 1 } Winning: { 1 } , { 2 } , { 3 } , { 4 } , { 5 } , { 6 } , { 7 } { 1 , 2 } , { 1 , 3 } , { 2 , 3 } , { 2 , 4 } , { 1 , 5 } { 1 , 1 , 1 } , { 1 , 1 , 2 } , { 1 , 2 , 2 } , { 1 , 1 , 3 }
The states that can be broken down into two identical halves are losing states because the second player wins by copying the first player's move on the other half.
Any state that consists of a losing state plus any one of the following operations must be a winning state (with the winning move being converting that state to the losing state):
Applying all of these steps to each of the losing states { 0 } , { 1 , 1 } , { 2 , 2 } , { 3 , 3 } , { 1 , 1 , 1 , 1 } gives all of the above winning states except { 1 , 5 } .
We determine that { 1 , 4 } must be a losing state because we have considered all states derivable from it in one move and they are all winning. From this we conclude that { 1 , 5 } is winning because it can be reduced to { 1 , 4 } in one move.
Now to add up the number of combinations for each of the above. We can encode the concept that the piles must have blank spaces between them by representing a pile of size n as n heads followed by one tail, and imagine we have 8 slots to fill. So for example p ( { 1 , 2 } ) is the number of permutations of { H T , H H T , T , T , T } , i.e. 5 ! / 3 ! = 2 0 .
It's a bit shorter to add up the number of losing positions and then subtract them from 1 2 8 :
p ( 1 , 1 ) p ( 2 , 2 ) p ( 3 , 3 ) p ( 1 , 4 ) p ( 0 ) p ( 1 , 1 , 1 , 1 ) = 6 ! / ( 4 ! 2 ! ) = 1 5 = 4 ! / ( 2 ! 2 ! ) = 6 = 1 = 3 ! = 6 = 1 = 1 which add up to 3 0 , so the number of winning positions is 9 8 .