Showing posts with label game. Show all posts
Showing posts with label game. Show all posts
Wednesday, March 23, 2022
Partition Game
Alice and Bob are playing a game as follows. Originally there are $n > 1$ piles containing $s$ stones each. Alice starts by taking the first turn and at each step, the player chooses one pile and discards the other piles. Then that player divides the stones from that one pile into $n$ piles, such that each pile still contains at least 1 stone. The player that cannot move loses.
Determine all $s$ such that Alice has a winning strategy
Solution
We classify every natural numbers into winning numbers or losing numbers with the following recursion: The numbers $1, \dots, n-1$ are losing numbers. If a number can be partitioned into losing numbers, then it's a winning number. Otherwise it's a losing number. In other words, any given partition of a losing number must contain a winning number.
Now the game is a standard Sprague-Grundy game. If a player receives a state where one pile contains a winning number, then that state is a winning state. For example, $n$ is a winning number because the player can split it into ones, regardless of what the other numbers in the pile are. If a player receives a state where all piles are losing numbers, then it's a losing state.
Let $m=n-1$.
Now we establish the base cases. $1, \dots, m$ are losing numbers. Then $n$ can be partitioned into all ones, and $mn$ can be partitioned into all $m$'s. It's easy to show that all the numbers in between can also be partitioned into summands between $1$ and $m$ inclusive, so $n,\dots,mn$ are winning numbers.
Now we claim: Let $x \equiv p \mod mn$ then $x$ is a winning number if and only if $p = 0$ or $p \geq n$, and it is a losing number if and only if $p \in [1,m]$. We prove it by induction on $k = \lceil x / mn \rceil$. The case of $k = 1$ is proven by the base case above.
Now suppose we have a number $x$ with residue in $[1,m] \mod mn$ and there is a way to partition this number into $n$ summands, all while staying within $[1,m] \mod mn$. The smallest sum (in the residue space) that can be attained is $n$, and the largest sum is $mn$, and they are all outside of $[1,m]$, a contradiction. So some of the summands must have residue $0$ or $\geq n \mod mn$. Let $y$ be this summand. Note that $ \lceil y / mn \rceil < \lceil x / mn \rceil$ in each of these cases. So $x$ is a losing number by induction hypothesis.
Now suppose we have a number $y$ divisible by $mn$, then we can partition it into $n$ numbers all having residue $m$. The easiest is of course to have the first $m$ terms $m$ and have the last term $y - m^2 = kmn - m^2 = (k-1)mn + m$. Each of these numbers are losing numbers with less quotient than $y$, so $y$ is a winning number.
Next, suppose we have $y$ with residue $[n, mn-1]$. Using the same argument as above, we can see that it can always be decomposed into the sum of $n$ numbers with residue $[1,m]$. However, the quotient of the summands are not necessarily less than $y$, but we have proved that the set in $[1,m]$ with quotient $k$ are losing numbers as well.
Friday, March 11, 2022
Toggling lights 3 at a time
Alice and Bob are playing a game. $n$ lights are put on a line with individual switches, initially all off. Then the two phases happen as follow:
1. Alice turns on some of these lights
2. Bob may do these actions: choose a contiguous block of 3 lights and toggle these 3 lights. He may repeat these actions as many times as he wants for different blocks.
And the scoring of the game is as follows:
In phase 1, Alice gets a -1 point for each light that she turns on. In phase 2, Alice gets a +1 point every time Bob performs an operation. Then at the end of the game, Alice gets $i$ points if light $i$ is on. Obviously Alice wants her score to be as high as possible, and Bob wants her score to be as low as possible. Determine the maximum points that Alice can get if both players are playing optimally.
Solution
Let $T_k$ denote the action by Bob of toggling a contiguous block of $k, k+1, k+2$, where $k \in [1, 98]$. If light $k+3$ is on and light $k$ is off, by performing $T_k + T_{k+1}$ he can turn off $k+3$ and turn on $k$. The net effect to the score is -1 so this move is beneficial to Bob. Therefore, he would keep doing it as long as there are lights on at $k > 3$. Furthermore, if there are 2 lights on $k > l$ such that $k \equiv l \mod 3$ then by repeating the operation above Bob can turn off both lights. The net effect to the score is $-k-l+2\frac{k-l}{3} < 0$. This means that it is not optimal for Alice to turn on two lights that have the same residue mod 3. So at most Alice should turn on 3 lights. But even then, if we ever arrive at the condition where lights $(1,2,3)$ are on, then Bob can perform $T_1$ to turn off all the lights. So Alice should turn on at most 2 lights.
The final condition that is most beneficial to Alice is either $(3)$ or $(1,2)$, both having the same value, and both are accessible from each other in phase 2. But obviously it's more beneficial for Alice to turn on only 1 light, and it should be the largest light divisible by 3, so that Bob has to spend a lot of moves moving it to the smaller number. So Alice should turn on $3\lfloor n/3 \rfloor$, and Bob will have to move it all the way to 3.
The total score is then $-1 + 2\lfloor n/3 \rfloor + 3 = 2\lfloor n/3 \rfloor +1$
Note: the number 3 can be replaced by a larger number $p$ but the principle is the same. Any light on above $p$ can be shifted down for a net gain for Bob. However, the final condition is tricky. Take $p=5$ for example. We don't want $(1,2,3,4,5)$ because then Bob can simply turn them all off in one fell swoop. We also don't want $(3,4,5)$ because Bob can still replace it by $(1,2)$ for a net gain. In fact, the optimal condition for Alice is $(3,5)$ because while Bob can replace it by $(1,2,4)$, it costs him 1 point to do so, so it's not a beneficial move for Bob. Likewise, for $p=6$, the best condition for Alice is $(5,6)$ because it's "just under" $(1+2+3+4+5+6)/2$. The number of lights that would be left on so that the sum is just under $n(n+1)/2$ is $\lfloor (n-1)/2 \rfloor$ which can be proved by induction. However, the exact configuration is harder to determine in closed form expression. This matters because in the course of shifting the lights down during phase 2, Bob may inadvertently have to perform the same $T_k$ twice in which case he would just not perform that action, so the calculation of final point count becomes more complicated.
Labels:
algorithm,
binary,
binary digit,
Combinatorics,
game
Thursday, July 22, 2021
Positive-definite Polynomial Game
Given $n$ a positive even number. Alice and Bob are playing a game as follows. On the board initially there are $n+1$ unassigned numbers: $a_0, a_1, \dots, a_n$.
With Alice going first, each player alternatingly chooses an unassigned number and assigns a positive real value to it. Once all numbers have been assigned values, polynomial $P(x)$ is defined as:
$$P(x) = a_nx^n + \dots + a_1x +a_0$$
If $P(x) > 0$ for all $x \in R$ then Alice wins, otherwise Bob wins. Determine who has a winning strategy.
Variant 1: if the number $a_0$ is already fixed to 1, so there are only $n$ numbers on the board, who has a winning strategy?
Variant 2: if the winning condition is flipped: Alice wins if there exists an $x$ such that $P(x) < 0$.
Solution
The player who moves last has a winning strategy, regardless of winning condition. Variant 1 merely flips who moves last. If Variant 1 is in play and Alice moves first, then Bob moves last and Bob has a winning strategy. Note that $P(x)$ is positive definite iff $tP(x)$ for all $t$ positive numbers, so the magnitude of each number doesn't matter, only the relative magnitude of all coefficients. Therefore, the number "1" set by variant 1 is arbitrary and the variant merely ensures Bob's ability to win. For the rest of this solution, we assume that variant 1 is not in play and Alice goes first, and she should assign $a_0 = 1$. The rest of the proof can then be extensible to variant 1 while flipping the name Alice and Bob.
Lemma: polynomial $P(x)$ with positive coefficients are positive definite if and only if $P(1/x) > 0$ for all $x \neq 0$. This lemma is easy to see because $P(0) > 0$ anyways.
Part 1: proving that Alice can ensure positive definiteness.
Assume that $a_0 = 1$ has already been assigned. Now divide the remaining coefficients into pairs: $(a_1,a_2), (a_3,a_4), \dots, (a_{n-1},a_n)$. Whenever Bob makes a move and assigns a value to a coefficient, Alice assigns a value to its pair accordingly. We claim that Alice will be able to choose her value such that the resulting polynomial $Q_k(x) = a_{2k}.x^{2k} + a_{2k-1}.x^{2k-1} + 2/n$ is positive definite.
Proof: From the lemma, $Q_k$ is positive definite iff $R_k(x) = \frac{2}{n}x^{2k} + a_{2k-1}x + a_{2k}$ is positive definite.
If Bob chooses $a_{2k-1}$ then Alice can choose $a_{2k}$ large enough to make $R_k(x)$ positive definite. Whichever local minimum may exist due to Bob's choice, Alice can compensate it enough by adding a positive constant term to the whole polynomial.
If Bob chooses $a_{2k}$ then there exists an $a_{2k-1}$ small enough to make $R_k(x)$ positive definite. If $x \geq 0$ positive then $R_k(x) > 0$ because all coefficients are positive. But if $x < 0$ then by AM-GM:
$$ \frac{2}{n}x^{2k} + a_{2k} = \frac{2}{n}x^{2k} + \frac{a_{2k}}{2k-1} + \dots + \frac{a_{2k}}{2k-1} \geq 2k \sqrt[2k]{\frac{2}{n}.\left(\frac{a_{2k}}{2k-1}\right)^{2k-1}}.(-x) > -a_{2k-1}x$$
for small enough positive value of $a_{2k-1}$.
The final polynomial can be expressed as the sum:$P = Q_1 + \dots + Q_{n/2}$, and because at each step Alice can always ensure that the resulting $Q_k(x)$ is positive definite no matter what Bob chooses, then the final polynomial is also guaranteed to be positive definite.
Part 2: proving that Alice can ensure non-positive definiteness.
If $n=2$ then Alice can always ensure that the discriminant of the quadratic polynomial is positive, therefore the polynomial has two real roots. For $n > 2$, the general strategy is as follows: divide the coefficients into pairs as above, and Alice's assignment is always the pair of Bob's assignment as well. But this time the difference is that, after each of her move, Alice ensures that the TOTAL polynomial $P(x)$ is negative for some values of $x$ and maintains this invariant throughout the game.
First note that if Bob ever chooses an even coefficient $a_2,a_4,\dots$ then Alice's job is really easy. Take the current value of $P(-1)$ (after including Bob's addition), and by choosing her corresponding odd coefficient large enough, she can make $P(-1)$ negative because she's adding a multiple of $x^{2k-1}$ which is negative at $x=-1$.
Consider the first round. If Bob chooses $a_{2k}$ then Alice chooses large enough $a_{2k-1}$ as described above. But if Bob chooses $a_{2k-1}$, Alice can choose small enough $a_{2k}$ to ensure non-positive definiteness. The current resulting polynomial is $a_{2k-1}x^{2k-1}+1 < 0$ as $x \to -\infty$, so pick any $y$ such that $a_{2k-1}y^{2k-1}+1 < 0$. Then Alice chooses $a_{2k}$ small enough such that $0 < a_{2k} < \frac{-a_{2k-1}y^{2k-1}-1}{y^{2k}}$ so that $a_{2k}y^{2k}+a_{2k-1}y^{2k-1}+1 < 0$
So once the invariant is established after the first round, then Bob has no choice but to keep choosing even coefficients. If Bob chooses an odd coefficient, then whichever value of $x$ caused $P(x)$ to be negative at the end of last round will continue to be (even more) negative, so Alice simply chooses a very small value of the corresponding even coefficient as described above. But even if Bob chooses an even coefficient, Alice can counter by choosing a large enough odd coefficient. Therefore she maintains the invariant of $P$ being non-positive definite until the end of the game.
Labels:
Algebra,
Combinatorics,
game,
polynomial,
positive definite
Monday, February 11, 2019
Game making expression positive definite
On the board there are six numbers $A,B,C,D,E,F$, all initially zero. Mary and Nancy are playing a game as follows. On Mary's turn, she increases one of $A,B,C$ by 1, and on Nancy's turn, she increases one of $D,E,F$ by 1. They take turns alternatingly until each has gone 2019 times. Each pair of turns is called a "set" (for example if Mary moves first, then 1 set consists of Mary's move followed by Nancy's move).
Winning condition: Mary wins if at any point at the end of a set the following inequality is true for all $x,y$ real numbers:
$$Ax^2 + By^2 + C \geq Dxy + Ex + Fy$$
Determine who has the winning strategy if:
1. Mary goes first
2. Nancy goes first
Solution
If Mary goes first Nancy has a winning strategy.
Replace $x$ with $x/z$ and $y$ with $y/z$ to make the inequality homogeneous:
$$Ax^2 + By^2 + Cz^2 \geq Dxy + Exz + Fyz$$
Note that the following form is always true if $u,v,w \geq 0$
$$u(x-y)^2 + v(x-z)^2 + w(y-z)^2 \geq 0$$
So if at any point after a set the inequality can be reduced to that form, then Mary wins. We claim the following two things:
1. That Nancy can always avoid that form, and
2. That if the form is not achieved then there exists a $x,y,z$ to make the inequality false
First to prove 1, note the following rearrangement:
$$u(x-y)^2 + v(x-z)^2 + w(y-z)^2 \geq 0$$
$$(u+v) x^2 + (u+w)y^2 + (v+w)z^2 \geq 2u xy + 2v xz + 2w yz$$
Therefore if $D = (A+B-C), E = (A+C-B), F = (B+C-A)$ then that form is achieved. This is the unique solution to achieve that form, and that solution may be negative. If the solution to that form contains negative number then no matter what Nancy does, that form is not achieved. But even if it is a triple of non-negative integers, Nancy has 3 choices of moves to make, so she still has at least 2 moves that won't result in that form.
Now to prove 2, we show that we can find $x,y,z$ that violates the inequality.
First, if $A,B,C$ do not form a triangle, then $A>B+C$ (or its permutation). Note that if we assume (WLOG) that $A>B+C$ then $A+B>C,A+C>B$. Furthermore WLOG we may assume that $B \geq C$.
$$Ax^2 + By^2 + Cz^2 \geq Dxy + Exz + Fyz$$
$$\iff (A+B-C)(x-y)^2 + (A+C-B)(y-z)^2 + (B+C-A)(x-z)^2 \geq -(2A+2B-2C-2D)xy - (2A+2C-2B-2E)yz - (2B+2C-2A-2F)xz$$
In that case we can choose the following variables. Let $S,R$ be large numbers. Let $x= 1/R, y = R + 1/R, z = SR + 1/R$. Then
$$ (A+B-C)R^2 + (A+C-B)(S-1)^2R^2 \geq (A-B-C)S^2R^2 + ...$$
The "..." part in RHS consists of terms $SR^2$ or lower. As we let $S,R$ become large, the dominant terms are $(S-1)^2R^2$ versus $S^2R^2$. For large enough $S$, $(A+B-C)+(A+B-C)(S-1)^2 < (A-B-C)S^2$. At that point we just fix $S$ but let $R$ become larger. Since the coefficient of $R^2$ in the RHS is larger, then the RHS grows faster, invalidating the inequality.
Now if $A,B,C$ form a triangle,
$$\iff (A+B-C)(x-y)^2 + (A+C-B)(y-z)^2 + (B+C-A)(x-z)^2 \geq (2A+2B-2C+2D)xy + (2A+2C-2B+2E)yz + (2B+2C-2A+2F)xz$$
Note that the sum of coefficients in RHS is zero, so the terms are not all positive. We shall divide into two cases: one positive two negatives or vice versa
Case 1: if the RHS is of the form $Uxy + Vxz - (U+V) yz$ with $U,V \geq 0$.
Then $$RHS = Uy(x-z) + Vz(x-y)$$
Then we set $x = R+1/R, y = R, z= R$. The terms in LHS will be zero or $(1/R^2)$ whereas the terms in RHS will be $(U + V)$. By setting $R$ large enough we can make LHS < RHS.
Case 2: if the RHS is of the form $(U+V)xy - Uyz - Vxz$ with $U,V \geq 0$
Then $$RHS = Uy(x-z) + Vx(y-z)$$
Then we set $x = R+1/R, y = R+1/R, z= R$. The terms in LHS will be zero or $(1/R^2)$ whereas the terms in RHS will be $(U + V)(1+1/R)$. Again, by setting $R$ large enough we can make LHS < RHS.
Challenge
Can you generalize this to third power and four variables? In other words, can the game be extended into the following inequality?
$$Ax^3 + By^3 + Cz^3 + Dw^3 \geq Exyz + Fxyw + Gxzw + H yzw$$
Answer: yes. We make use of the following property: $f(a,b,c) = a^3 + b^3 + c^3 - 3abc = (a+b+c)((a-b)^2 + (b-c)^2 + (c-a)^2)/2 \geq 0$
If the inequality can be expressed as a positive sum of $f(x,y,z), f(x,y,w), f(x,z,w), f(y,zw)$ then the inequality holds. If not, then there are two cases:
1. One or more of the $f$ form occurs on the RHS, in which case we choose $x,y,z,w$ to maximize the growth of the ones in the RHS. For example, $x=y=1/R, z = R+1/R, w = SR + 1/R$ for large $S,R$.
2. The $f$ forms all occur on the LHS, so there are terms of $xyz$ etc on the RHS whose coefficients all sum to zero. We can pick $x,y,z,w$ whose differences are small but themselves are large, such as $x=R, Y = R+1/R, z = R+2/R, w = R+3/R$. That way, the values of $f$ will be small but values of $xyz$ will be big. By judiciously permuting those values depending on which coefficients are negative, we can make LHS to be < RHS.
Saturday, May 5, 2018
Moving coins across the board
On a $1 \times 2018$ chess-board, the $n (n < 2018)$ left-most squares contain 1 coin each. Alice and Bob are playing a game, where on each turn the player may choose a coin and move it to the right one or two units. The only condition is that each square may only contain one coin at a time (no "stacking"), except the last square (right-most square). Alice goes first. The player who cannot make a legal move loses. Determine all $n$ such that Alice has a winning strategy.
Solution
Label each square by its distance from the right-most square. So the right-most square is called square zero, and the left-most square is called square 2017. Suppose $(a_1, a_2, \dots, a_k)$ denotes the condition that there is a coin on each of the cells $a_1, \dots, a_k$ and the rest of the coins are in the square zero. WLOG, we may assume $a_1 < a_2 < \dots < a_k$.
Claim:
We claim that $(a_1, \dots, a_k)$ is a losing position if and only if $a_1 + \dots + a_k$ is divisible by 3.
First note that the game ends only when there's no more legal move left, and that's when all the coins are on square zero. So as long as the sum of the coin numbers are greater than zero, there is always a legal move available. At the very least, the coin with the lowest number can be moved to the right 1 or 2 steps (possibly reaching zero in the process).
Lemma:
If the sum of the numbers are not divisible by 3, there is always a legal move to make it divisible by 3 within one turn.
Note that our claim is a corollary of the lemma. If the sum of the numbers is divisible by 3, then no matter what move you do, you can only reduce it by 1 or 2. Based on the lemma, the opponent can always counter it by bringing down to the next multiple of 3. Therefore, your opponent will never face the situation without any legal move. Conversely, if it's not divisible by 3, you can always bring it to a multiple of 3 within one turn so that your opponent is facing a losing position next. And your winning strategy is always to keep the sum of the numbers divisible by 3.
Proof of lemma:
If the the sum of the numbers is $3m+1$, then you only need to move the lowest-numbered coin down by 1. This is always possible because it is at least 1. If the sum of the numbers is $3m+2$, then you need to move ANY coin down by 2. Suppose that this is not possible, either due to prospect of collision or running against the end of the board. That means the following:
1. There are no two consecutive empty cells. If there are two or more consecutive empty cells, then the coin to the left of that block can be moved down by two. This means that $a_i - a_{i-1} = 1,2$ for each $i$.
2. There is nothing on cell 2, because otherwise we can always move it to cell 0 directly.
3. There is no "jumping over" possible. Meaning, if cell $x$ is empty but $x+1,x+2$ are both occupied, we can take $x+2$ and move it to $x$. So this configuration is not allowed: EMPTY, OCCUPIED, OCCUPIED.
This means cell 1 has a coin on it. $a_1 = 1$. Since 2 is empty, then 3 must have a coin on it ($a_2 = 3$). If 4 has a coin on it, then it violates condition 3 above, so 4 must be empty. That means 5 must be occupied (by condition 1). We can continue this pattern indefinitely, to arrive at the conclusion that current condition must be: $(1,3,5, \dots, 2k-1)$. The sum of the numbers is therefore $1 + 3 + \dots + 2k-1 = k^2$, which cannot be $3m+2$. Contradiction. Hence it's always possible to choose a coin to move down by 2. This completes our proof of the lemma.
Now, the initial condition is $(2018-(n-1), 2018-(n-2), \dots, 2018)$, so that the sum of the numbers is: $n(4037-n)/2$. For this to be divisible by 3, either $n$ is divisible by 3, or $n \equiv 2 \mod 3$. These are the losing positions. So in order for Alice to have winning strategy, $n \equiv 1 \mod 3$.
Labels:
Combinatorics,
game,
induction,
invariant,
Sprague-Grundy,
turn,
winning-strategy
Thursday, May 3, 2018
Marbles in 3 buckets
Given 3 buckets, each containing $n$ marbles. Alice and Bob are playing a game, where on each turn, the player may remove 1, 2, or 3 marbles from a single bucket. Alice goes first. The player who removes the last marble wins. Determine all $n$ such that Alice has a winning strategy.
Solution
If $n$ is divisible by 4 then Bob has a winning strategy, and if $n$ is not divisible by 4 then Alice has a winning strategy.
First note that $(4m,k,k)$ is a losing position for any $k \geq 0,m > 0$. Because if you remove $p$ marbles from the first bucket, your opponent may remove $4-p$ marbles to go back to $(4(m-1), k k)$. And if you remove from any of the second or third pile, your opponent may mirror that to go back to $(4m, k-p, k-p)$. Thus, no matter what you do, your opponent always has a legal move to make.
Therefore if $n$ is divisible by 4, assuming Bob plays optimally, Alice loses the game.
But if $n$ is not divisible by 4, say $n = 4m+a, a=1,2,3$. Then Alice may remove $a$ from the first bucket, to arrive at $(4m,n,n)$ which is a losing position for Bob.
Generalization
If there are $n$ buckets of $n$ marbles, we can employ the same strategy. The goal is to force your opponent into a "symmetric" situation where no matter what he/she does, you can always mirror it.
If $n$ is divisible by 4, then $(n,n,\dots,n)$ is a losing position because no matter what you do, your opponent can always mirror it. In general, the situation where there are an even number of buckets left and each pair of buckets contains the same number of marbles is a losing position.
If $n=4m+1,4m+3$, then you can employ the same strategy as above. Alice transforms the configuration into $(4m, a,a, b,b, \dots, z,z)$ and from there no matter what Bob does, Alice can always mirror it.
Variation
Now, suppose there's only $n$ marbles total and it is to be distributed among all 3 buckets, with each bucket containing at least one marble. Alice determines the distribution, and Bob makes the first "regular" turn. Determine all numbers $n$ such that there exists a way for Alice to distribute in such a way that Bob always loses.
Solution
At this point, we have to characterize the conditions in which configuration $(a,b,c)$ is a losing position. It's clear to see that $(a,0,0)$ is a losing position if and only if $a \equiv 0 \mod 4$.
Now consider the configuration $(a,b,0)$. If $a \equiv b \mod 4$ then this is a losing position, because the opponent can always mirror you move to keep the condition true. Therefore, if $a \neq b \mod 4$, it is a winning position because we can turn it into the above-mentioned losing position for our opponent.
Now consider the configuration where there are three non-zero buckets left. As we saw above, $(4a,b,b)$ is a losing position because your opponent can always mirror your steps, and restoring to original configuration, and consequently, $(a,b,b)$ is a winning position if $a \neq 0 \mod 4$ because you can turn it into the form $(4a,b,b)$.
We can take this reasoning one step further by claiming, the configuration $(a,b,c)$ where $b \equiv c \mod 4$ is a losing position if and only if $a \equiv 0 mod 4$. Indeed, if $a$ is divisible by 4, then any move you make in the first bucket will be countered in the first bucket, and any move you make in the second or third buckets will also be countered to keep $b \equiv c \mod 4$. Thus either you will bring $a$ below 4 and your opponent can empty the first bucket, leaving you to $(0,b,c)$ which is a losing position, or you will empty one of the second or third buckets first. In the latter case, then your opponent can still mirror it to arrive at $(a,0,c)$ where both $a,c$ are divisible by 4, which is a losing position. Conversely, if $a$ is not divisible by 4, you can make it divisible by 4 to be a losing position for your opponent.
Finally we prove that $(a,b,c) \equiv (1,2,3) \mod 4$ is a losing position, because any move that is made from here will result in a winning position. If we take from first bucket, we now get $(2/3/0, 2,3) \mod 4$ all of which are winning positions. If you take from second bucket, we get $(1, 3/0/1, 3)$ also winning positions, similarly if we do from third bucket. The point is that there is no way to avoid $(a,a,b)$ form where $b $ is not divisible by 4, or $(0,a,b)$ form.
Thus, if $n > 4$ is even, Alice has a winning strategy as follows. If $n = 4m$ then Alice distributes the marbles as $(4(m-1),2,2)$. If $n=4m+2$ she distributes it as $(4m,1,1)$. Both are losing positions Bob. But if $n=4$, then Bob has a winning strategy. Alice has no choice but to distribute the marbles as $(1,1,2)$ initially, and Bob can turn it into $(1,1,0)$ which is a losing position for Alice.
If $n$ is odd, Bob has a winning strategy no matter how Alice distributes the marbles. If all the three buckets contain odd number of marbles, then two of them will be congruent modulo 4, and the third one will not be divisible by 4, and that is a winning position for Bob. If two buckets contain even numbers and the third one odd, we have two choices. Either the two even buckets are both $\equiv 2 mod 4$, which means it's still a winning position for Bob, or at least one of them is divisible by 4, which is also a winning position for Bob.
Bottom line, Alice has a way to distribute the marbles into a losing position for Bob if and only if $n$ is even and $n > 4$.
Wednesday, May 2, 2018
Marking number game
Let $n > 2$ be an even number. On the board, there are numbers $1, 2, \dots, n$, and initially the number 1 is marked, and no other numbers are marked. Alice and Bob are playing a game, with Alice moving first. On each turn, they may choose a number $k$ that is currently unmarked, and mark it, provided: $k+1$ was previously marked, OR $k$ is even and $k/2$ was previously marked. The player who gets to mark the number $n$ wins the game.
Determine all $n$ such that Alice has a winning strategy.
Solution
As soon as one player marks $n/2$, then he/she loses, because the opponent can mark $n$ directly after that. Also, the number $n$ can be marked ONLY after $n/2$ is marked (by virtue of $n/2$ being marked, since there is no number $n+1$ on the board). Therefore, the crux of the game is to avoid the number $n/2$ at all costs.
Suppose $n = 2m$. Define the numbers in set $\{ 2,3,\dots, n-1 \}$ to be "accessible" if it can be marked without ever marking $m$. Obviously $m$ is not accessible. Let $A$ be the set of accessible numbers. For example, for $n=12$ the accessible numbers are: $A = \{ 2, 3, 4, 7, 8 \}$. Note that 6 is not accessible by definition. 5 is not accessible because in order to mark 5, we'd have to go through 6. 11 is not accessible because it can't be reached without marking 12, which has to go through 6. 10 is also not accessible because it can only be reached through 11 or 5, both of which are not accessible. Therefore 9 is also not accessible.
Now, as long as there's an unmarked number in $A$, then the current player can always choose a legal move to play. Not all unmarked numbers in $A$ will be eligible to be marked, but by the construction of $A$, we can reach that number through other numbers that have been marked (and therefore also in $A$), so as long as there exists an unmarked number in $A$, there is a legal move to be played.
As soon as all numbers in $A$ are marked, then the next person has to mark $m$, and the other player can win immediately. In the case of $n=12$ above, 10 will not ever be marked because as soon as 6 is marked, the next person marks 12. Therefore the winner of the game (assuming both sides play optimally) depends on the parity of $|A|$. Alice has a winning strategy if and only if $|A|$ is odd.
Generally all the numbers from $\{2, 3, \dots, 2m-2 \}$ are accessible, with a handful of exception. $m$ is by definition inaccessible, and $2m-1$ is also inaccessible. So we want to list all the numbers that are not accessible. We divide into two cases.
If $m$ is odd:
Consider the sequence: $1,2,4,3,6,5,8,7, \dots, 2k, 2k-1, 2k+2, 2k+1, \dots, 2m-2, 2m-3$. That is a legal sequence to mark numbers. Therefore, almost all numbers in the set $\{2, 3, \dots, 2m-2 \}$ are accessible except $m$, because we can simply go through the sequence, and only skipping $m$. No further interruption to the sequence will occur because the highest number in the sequence is $2m-2 < 2m$ so it's not affected by the fact that $m$ was never marked. Thus, $A = \{2, \dots, 2m-2 \} - \{ m \}$, and $|A| = 2m-4$. This means Alice does not have a winning strategy because Bob has a winning strategy.
If $m$ is even:
Same as before, we go through the sequence, but skipping $m$. This has several ramifications. First, because $m$ is even, then $m-1$ is not accessible. Thus, there are two numbers that are also "deleted" from that sequence later on: $2m-2, 2m-3$. The rest of the sequence is not affected, because $m+2, m+4,m+6,\dots, 2m-4$ can still be marked. Thus: $|A| = 2m-3 - 4 = 2m-7$. This means Alice has a winning strategy.
This reasoning breaks down when $m=2$ because then $2m-2 = 2$ so there was no other choice and Bob wins. But this is the only corner case.
Therefore, Alice has a winning strategy if and only if $n > 4$ and $n$ is divisible by 4.
Wednesday, February 5, 2014
Betting on cards
A deck consisting of $n$ red cards and $n$ black cards are shuffled. The cards are then flipped one at a time. Before each flip, you are allowed to make a bet on the color of the next card. If you guessed right, you win an amount equals to your bet. If you guessed wrong, you lose your bet. You don't have to bet on every flip, in fact you don't have to bet at all if you so wish. The bets can be any amount of real number, and you start with one dollar.
You decide to employ the following strategy. Suppose that, by counting already-flipped cards, you deduce that there are $R$ red cards and $B$ black cards left in the deck. If $R > B$, you guess red while betting $\frac{R-B}{R+B}$ of your total money. Similarly if $R < B$ you guess black while betting $\frac{B-R}{B+R}$ of your total money. If $R=B$ you don't bet that turn. Show that this strategy guarantees a final amount of:
$$\frac{2^{2n}n!n!}{(2n)!}$$
Note: this final amount is much bigger than people think. That sum equals to:
$$\left(1 + \frac{1}{2n-1} \right) \left(1 + \frac{1}{2n-3} \right) \dots \left(1 + \frac{1}{3} \right) \left(1 + \frac{1}{1} \right)$$
which is already greater than 2, and only increases as $n$ increases. This is an extension to the obvious strategy to wait until the last card before we bet the one dollar that we start with, to which we'd be guaranteed a final amount of two.
First Solution
First we claim the following: if at any point there are $R$ red cards and $B$ black cards left in the deck, and your current total is $x$, employing the above strategy will give you a final amount of: $$\frac{2^{R+B}R!B!}{(R+B)!} x$$ That claim is easily verified if either $R+B=1$ because then we would know exactly what's left in the deck. Now we prove the claim by induction on $R+B$. Clearly if $R=B$ then we don't bet that flip, and we reduced it to the case $R+B-1$. But if $R \neq B$, and WLOG we may assume that $R > B$. We bet $\frac{R-B}{W+B}$ that the next card will be red. Case 1: the next card is red. That means our current total becomes $(1 + \frac{R-B}{R+B})x = \frac{2R}{R+B}x$. But the deck now contains $R-1$ red and $B$ black, so by our induction hypothesis, our final amount will be: $$\frac{2^{R+B-1}(R-1)!B!}{(R+B-1)!} \frac{2R}{R+B}x =\frac{2^{R+B}R!B!}{(R+B)!} x $$ Case 2: the next card is black and we lost our bet. That means our current total is now $(1 - \frac{R-B}{R+B})x = \frac{2B}{R+B}x$ and the deck contains $R$ red and $B-1$ black, so our final amount is: $$\frac{2^{R+B-1}R!(B-1)!}{(R+B-1)!} \frac{2B}{R+B}x =\frac{2^{R+B}R!B!}{(R+B)!} x $$ And the claim is proven. Now it's straightforward to apply that if $R=B=n$, we have: $$\frac{2^{2n}n!n!}{(2n)!} = \frac{(2n)(2n-2)\dots (4)(2)}{(2n-1)(2n-3) \dots (3) (1)}$$ $$= \left(1 + \frac{1}{2n-1} \right) \left(1 + \frac{1}{2n-3} \right) \dots \left(1 + \frac{1}{3} \right) \left(1 + \frac{1}{1} \right)$$
Labels:
Algebra,
card,
Combinatorics,
counting,
game,
probability
Thursday, October 22, 2009
Boys and Girls around the table
$(n+1)$ boys and $n$ girls are seated around a circular table playing a game. One boy started to put a stone on the table, and they subsequently went around the table clockwise. At each child's turn, if that child is a boy, he puts a stone on the table, but if that child is a girl, she takes away one stone from the table. They're finished when everyone has had one turn. If the table ever becomes empty (except before the first boy put his stone), they all lose the game.
Prove that there is a boy such that if he starts, they can complete the round without losing.
Furthermore, prove that there is only one such boy. That is, if any other boy starts, they would lose the game.
Harder version: suppose you now have $m+n$ boys and $n$ girls, with $m$ positive. Prove that there are exactly $m$ boys who could start a non-losing game.
Prove that there is a boy such that if he starts, they can complete the round without losing.
Furthermore, prove that there is only one such boy. That is, if any other boy starts, they would lose the game.
Harder version: suppose you now have $m+n$ boys and $n$ girls, with $m$ positive. Prove that there are exactly $m$ boys who could start a non-losing game.
Friday, October 9, 2009
Room and Lights Game
This problem is identical to this one but reworded for better clarity.
Alice is playing a game against Bob and Charlie. In a room, there are 27 lights with individual switches, some of them could be turned on or off. Bob enters the room while Charlie waits outside. Alice will tell Bob a number from 1 to 27. Bob then is allowed to flip at most 3 switches if he wishes. Then Bob exits and Charlie enters the room. He has to, upon examining the lights, guess the number that Alice told Bob. Neither Bob nor Charlie knows the configuration of the lights before Bob entered the room.
How can Bob and Charlie agree on a strategy to win this game?
Harder version: 15 lights, but Alice tells Bob a number from 1 to 16, and Bob can only flip at most one switch.
Alice is playing a game against Bob and Charlie. In a room, there are 27 lights with individual switches, some of them could be turned on or off. Bob enters the room while Charlie waits outside. Alice will tell Bob a number from 1 to 27. Bob then is allowed to flip at most 3 switches if he wishes. Then Bob exits and Charlie enters the room. He has to, upon examining the lights, guess the number that Alice told Bob. Neither Bob nor Charlie knows the configuration of the lights before Bob entered the room.
How can Bob and Charlie agree on a strategy to win this game?
Harder version: 15 lights, but Alice tells Bob a number from 1 to 16, and Bob can only flip at most one switch.
Subscribe to:
Posts (Atom)