@byorgey
.
Here’s my initial entry to the #proofinatoot
contest—the idea is to write a proof that fits in Mastodon’s 500-character limit for “toots” (you know, like a tweet, but more mastodon-y). To fit this proof into 500 characters I had to leave out a lot of details; it was a fun exercise to take a cool proof and try to distill it down to just its core ideas. Can you fill in the details I omitted? (Also, can you figure out what word is commonly used to refer to graphs with these properties?)
Let be a graph with . Any two of the following imply the third: 1. is connected; 2. is acyclic; 3. has edges.
: by induction. Any walk must reach a leaf. Delete it and apply the IH.
: by induction. Sum of degrees is , so there are at least two leaves. Delete one and apply the IH.
: Let have connected components. Since for each, the total number of edges is , hence .
In practice, instead of thinking about trees, we can just keep an upper-triangular matrix , where will denote Alice’s best score from the point when only coins are left. (The matrix is upper-triangular since this only makes sense when .) We can also keep a separate upper-triangular matrix where is the best move when coins are left ( means that both moves are equally good).
When coins are left, either coin or coin will be taken, leaving coins or . So, if we already know the values of and , we can use them to compute the optimal value for (and to decide which move is better). This corresponds to the observation that we can compute the value at a node in the game tree as long as we already know the values at both of its children.
Here is one way to visualize these tables, turned diagonally so it ends up looking very similar to the compact trees from my previous post; each cell corresponds to the coins along the base of the triangle which has that cell as its apex. The light blue square in each cell shows the value of ; the arrows indicate the best move(s) , with blue arrows for Alice’s moves and green for Bob’s.
For example, the top cell says that from this state (when all four coins remain) Alice will get 5 points with best play, and the two blue arrows mean that it does not matter which coin Alice takes. Suppose she takes the , so the are left. The corresponding cell is the cell at the apex of the triangle whose base is :
So now Bob can look at this cell to see what his optimal play is. He can see that from this position Alice will get 2 more points if they both play their best. He can also see from the green arrow that his best move is to move into the cell below and to the left, that is, to leave Alice with the coins —which means he should take the coin on the right, namely, the . Finally, Alice’s best move in this situation is to take the on the right, with the blue arrow pointing to what Bob is left with.
Using this visualization we can easily look at bigger games. For example, in my first post I left readers with the challenge of analyzing this game:
From the table we can now see that Alice will score points with best play, and that her best move is to start by taking the (the blue arrow points to the right, so she should take the on the left in order to send Bob to the game on the right). It doesn’t matter which move Bob plays next, and then Alice will take either the or the , depending on Bob’s move, and so on.
One nice thing to note is that these tables don’t just tell us what should happen when both players play optimally. They tell us the optimal play in any subgame. In other words, one could say that they even show us how to best capitalize on mistakes made by our opponent. To play the greedy coins game perfectly, first just compute the tables and (actually, this is not too hard to learn how to do by hand, especially if you use the above format). Then when it is your turn, if coins remain just look up to see what your best move is. If you have used the above format you don’t even need to bother with keeping track of the indices and ; just find the remaining coins along the bottom and find the apex of their triangle. (In addition to finding your best move you can also confidently, and annoyingly, announce to your opponent that you will get at least points no matter what they do; for extra annoyingness, you can let your opponent choose your move whenever the move table tells you that both moves are optimal.)
Just for fun, here’s an analysis of the slightly larger game , which is a counterexample to one of my original conjectures about tied games:
One final thing I will mention is that it’s hard to tell from looking at Alice’s total score whether the game is tied, or how much Alice will win by. Of course we can compute it if we know the total value of all the coins: Alice will win by the difference between her total and half the total coin value. But it might be nicer to directly visualize not Alice’s total score but the margin of her victory over Bob. This is related to the function defined by Eric Burgess in a previous comment; more on this in a future post.
However, there is one big problem: for a game of length , this tree will have approximately nodes. Even for a reasonable-sized game of, say, coins (which is, of course, the official standard size used at the annual International Greedy Coins Championship, or IGCC), such a tree would have over one million nodes! And we only have to get up to or so coins—a big game, to be sure, but well within the realm of possibility—before the resulting tree would have more nodes than there are atoms in the universe. (!!)
But there is one important detail that saves us: these trees have a lot of repetition. Look again at the tree for :
Notice how the game occurs twice on the third level of the tree, because there are two ways to get there: Alice could take the 3 and then Bob could take the 1; or Alice could take the 1 and Bob could take the 3. Of course these are different play sequences and result in different overall results for Bob and Alice; but in either case they end up in the same position: with coins and on the table with Alice to move. Likewise, notice that the game consisting of just a single occurs three times (the sequences RRL, RLR, and LRR all lead to it), as does the game consisting of just a single .
There is a very nice way to draw the tree of possibilities that avoids this duplication:
Each possible subgame occurs exactly once, and there may be multiple paths that can be used to reach it. For example, there are three different paths that end in the single at the bottom: RRL, RLR, and LRR. Of course, these correspond exactly to the three copies of that we saw in the previous tree. In general, after we have taken the leftmost coin times and the rightmost coin times, we will have remaining coins through —and the order in which those coins were taken does not matter; we end up with the same remaining coins in any case. (Can you say how many different paths we could have used to get there?)
We can now analyze this compact “tree” in the same way as we did previously (start from the bottom and work our way up by alternating levels); the only difference is that we are no longer doing any redundant work!
This works precisely because we can analyze each subgame independently of the path taken to get there: the best play from a given point onwards is not influenced by the order of moves that came before. Given that we have already analyzed all the games in one level of the tree, we can use them to analyze the games one level up, and so on, until we reach the top.
Previously, the tree for a game of length had about nodes; now we can see that in these compact “trees”, there are games on the bottom row, on the next row up, on the next, and so on, for a total of
nodes. This is much, much better! Remember how drawing the entire tree for coins would require more nodes than there are atoms in the universe? Well, is only —a number which is, shall we say, slightly smaller. While I still wouldn’t particularly want to draw the whole compact tree by hand, having a computer analyze it is entirely feasible. And not just feasible in the sense of theoretically possible; practically speaking, by analyzing a compact game tree, any modern desktop computer could compute the optimal play for a -coin game in a fraction of a second.
Recall that we were using this example game:
We can draw out the tree of all possible sequences of moves, like this:
Now, let’s work from the bottom up, computing the best score for Alice at each point. First, the bottom row of the tree corresponds to the point when there is only a single coin left, and it is Bob’s turn. Bob has no choice, and Alice can’t get any more coins. In general, we will put Alice’s best score in a blue square next to each node. Since Alice can’t get any coins at this point in the game, we put a zero next to each game on the bottom row:
Now consider the next row up. In these games, it is Alice’s turn. She wants to maximize her score, so she should pick the coin which gives her the biggest total. Her total will consist of the value of the coin plus the zero she will get from that point on—that is, just the value of the coin.
Notice how in each case we have highlighted Alice’s best move in blue, and written Alice’s best score from this point on in the blue square next to each game. So, for example, in the leftmost game, where only and are left, Alice should take the , and this will give her a total score of .
Considering the next row up, it will be Bob’s turn in these games: of course, he will play so as to minimize Alice’s total score (which is the same as maximizing his score, since the scores always add up to the total value of all the coins). So he should look at the scores Alice will get (i.e. the numbers in the little blue squares) and pick the move that will lead to the smallest number for Alice.
Notice how in the left-hand game (), Bob’s best move is highlighted in green: he should take the , since this will lead to a game in which Alice will get a total of , which is better than his other choice, which will lead to Alice getting . In the right-hand game, it doesn’t matter what Bob picks: Alice will get in either case. So neither move is highlighted for Bob.
We have again written the best score Alice can expect to get from this point on in a little blue square to the right of each game. From the discussion above we can see that for this row (and any even row in general) this will just be the minimum of Alice’s score values from the level below.
Finally, considering the top node, we can analyze Alice’s choices: she can either take the on the right, which leads to a game in which we know she will get more, for a total of ; or she can take the on the left, which leads to a game in which she will get more, again for a total of . So in this case it doesn’t matter which move Alice picks. We write the total in a little blue square to the right of the game, and highlight neither move since either one is optimal. The final analyzed tree looks like this:
At each turn, a player has only two choices, to take the left coin or the right coin. If we record the sequence of right-or-left choices made by the players, we can easily reconstruct the state of the game at each point and the total score for each player. For example, suppose we start with the game
and that the players make the sequence of choices . This means that Alice first took the coin on the right, namely, the 3, thus leaving ; next, Bob took the coin on the right, that is, the 4, leaving ; then Alice took the 1 on the left; and finally, Bob took the only coin remaining, the 2. So Alice’s total is 4, and Bob’s is 6 (Alice did not play very well!). Note that on his last move Bob has no choice at all, since there is only one coin left, which is why we had a sequence of three choices instead of four. In general, for a game with coins, playing the game will result in a sequence of R’s and L’s. Since each move is completely independent of the other moves, there are a total of such move choice sequences.
We can easily list all the possible sequences of R’s and L’s, and compute the resulting score from each. Then we just see which is the biggest, right? Well… not so fast! The biggest possible score for Alice will actually come from the game where Alice plays her best and Bob plays his worst, which is not what we want to know. (Actually, it’s even worse than that: the biggest score comes from Alice playing not the best moves, but the moves that she knows will be the best assuming that Bob plays his worst. That is, her highest possible score might come from playing moves that “shouldn’t” be her best moves, but since Bob will screw up they end up being better than they should be!)
Instead of just blindly evaluating the score from each possible sequence of moves in isolation, we can arrange all possible sequences of moves in a tree, like this:
Each node in the tree corresponds to a position in the game, and has two edges coming out of it corresponding to the two possible choices which could be made by the player whose turn it is. It may seem like I have labelled the edges “backwards”, but when a player takes the coin on the right, it is the coins on the left that remain, and vice versa, so it looks a bit nicer to arrange the tree this way.
Now, when it is Alice’s turn she will be trying to play so as to maximize her score. But Bob will be instead trying to minimize Alice’s score. So we can compute the best overall play by working our way up the tree: for a node where it is Alice’s turn, once we know her score with best play in either subtree, we can pick the move for her that will maximize her score. Likewise, for a node representing Bob’s turn, we can pick the move for him that will minimize Alice’s score. If we keep working our way up the tree in this way, level by level, we can compute the optimal score for Alice (and what moves she should play to get there). Soon I plan to draw a nice picture of how this process works, but it’s taking me a while to create and I didn’t want to hold up this blog post any longer!
So, this works, but there is one big problem: this tree has approximately nodes, which gets very big, very fast. Even if we bump up to a game with 6 coins instead of 4, we can see that the tree is already quite a bit bigger (four times as big, in fact):
And with eight coins it is already looking ridiculous:
There’s one more important observation we can make about these trees which will allow us to cut out a lot of unnecessary work, and avoid having to deal directly with such enormous trees—which I will explain next time!
In my previous post I reported that Thibault Vroonhove had conjectured the following strategy to be optimal for Alice:
If the two end coins have unequal values, and the larger of the two is also larger than its neighbor, take it.
Otherwise, look at the alternating totals (i.e. the total of the “red” coins and the total of the “blue” coins). Take the end coin corresponding to whichever group has the higher total.
If neither of these rules apply then it doesn’t matter which coin Alice takes.
Note that if the first rule applies, Alice definitely wins by following it: this was proved in a comment by Eric Burgess (though I don’t think it is clear whether this would always be Alice’s best play). The proof is actually not hard to understand (it is obscured a bit in Eric’s presentation because he was trying to investigate something more general): if Alice takes a coin which is bigger than either of the coins Bob could take next, she will be ahead after those two turns. Then it will be Alice’s turn, and it will be as if they are starting a brand new game. But we know that Alice can always at least force a tie. So since she gets ahead after the first two moves and can force the rest of the game to be a tie, she will win.
Now, it turns out that it can matter which coin Alice takes if neither of the two rules apply. Consider the game :
Neither of the rules apply here: the bigger end number, 3, is not bigger than its neighbor, and considering sets of alternating coins we have . However, it matters which coin Alice takes: her only winning move is to take the 3 (she will win by 2). If she takes the 2, the game will be a tie.
Thibault then modified his conjecture to add a third rule: if neither of the first two rules apply, Alice should play to minimize her local loss, that is, she should play so as to maximize the difference between the coin she takes and the larger of the two coins left to Bob. Unfortunately, this does not work either: I wrote a program to search for counterexamples, and it came up with .
The 3 is not bigger than its neighbor (5) so the first rule does not apply.
, so the second rule does not apply either.
The third rule would now tell Alice to take the 2: the biggest coin left to Bob after taking the 2 is the 3, giving Alice a local loss of 1; on the other hand, if Alice takes the 3, the biggest coin left to Bob is a 5, for a local loss of 2. However, it turns out that taking the 3 is actually Alice’s best move: she will win by 2. On the other hand, taking the 2 results in a tie.
Ultimately, based on my experience with solving these sorts of problems from a computational point of view, I am skeptical that this sort of approach can work. In my next post I will explain how Alice can compute an optimal strategy, but the time (and memory) needed for the computation scales quadratically with the size of the game; that is, finding the optimal play for a game of length takes time proportional to . By contrast, note that Thibault’s strategy takes time linear in . I conjecture that the optimal strategy actually cannot be computed in sub-quadratic time. (I would really love to be proven wrong, though, because I think one could use a linear-time algorithm to play perfectly against one’s friends—a great party trick if you go to the right sort of parties—whereas I doubt a quadratic algorithm would be feasible to do quickly enough in one’s head.)
Finally, I will note that in the comments to my previous post, Eric Burgess made some great strides in understanding the theory of the game. I hope you will be able to read more about that soon!
In my previous post I conjectured that the only tied games are the ones that can be built up by surrounding a tied game with a coin () or concatenating two tied games (). That conjecture was quickly shot down, with commenters tinyboss and Thibault Vroonhove independently pointing out counterexamples: or are both tied, even though they can’t be built up in the conjectured way. As you can check, with best play in these games, one player will get and the other will get .
Thibault noted that these particular tied games can be made by starting with a symmetric game (like ) and then adding the same number to all the coins in one half (e.g. adding to each coin in the second half of yields ). However, although I think this always yields a tied game for games of length 4, it turns out that this does not always result in a tied game in general: for example, isn’t tied, since the coins add up to an odd total.
Thibault then came up with a counterexample to my other conjecture, namely, that is tied if and both are: is not tied, even though it is the concatenation of two tied games. In fact, even is not tied: Alice can guarantee that she will get at least three of the s.
Given all this it’s kind of amazing that the big game I constructed as a quick test of my conjectures, namely , is indeed tied. Eric Burgess reported that in fact every cyclic permutation of this game is tied!
Eric also introduced the function , where denotes the winning margin, with best play, of whoever’s turn it is. That is, starting from position , with best play, what is the difference between the current player’s score and the other player’s? (Note that in the case of Bob the “winning margin” can be negative, if Bob is going to lose even with best play.) If the current player takes coin , then denotes the winning margin of the other player from that point on, which is the same as the losing margin of the current player. But they also got ; so overall their winning margin will be . Of course, best play means that the current player will choose whichever coin gives them the higher winning margin. This motivates the following inductive definition of , where we use to denote the maximum of and :
Thibault conjectured that the following strategy for Alice is optimal (I’ve rephrased it in a way that I’m pretty sure is equivalent, and which I think makes it more clear):
If the two end coins have unequal values, and the larger of the two is also larger than its neighbor, take it.
Otherwise, look at the alternating totals (i.e. the total of the “red” coins and the total of the “blue” coins). Take the end coin corresponding to whichever group has the higher total.
If neither of these rules apply then it doesn’t matter which coin Alice takes.
If this strategy is indeed optimal, that would be really cool, since it is pretty easy to apply in practice. But I am not ready to say whether I believe this conjecture or not. In any case it should be possible to test this strategy with a computer program to play lots of random games, which I hope to do soon (and to write another post about it).
Color the coins alternately red and blue, like this:
Note that if she wants, Alice can play so as to take all the red coins and force Bob to take all the blue coins, or vice versa. For example, if she wants all the red coins, she starts by taking the red coin on the end, leaving Bob with no choice but to take a blue coin. Bob’s choice then exposes another red coin for Alice to take, leaving Bob with only blue coins to choose from, and so on. Symmetrically, Alice could always take the one available blue coin on her turn, leaving Bob with no choice but to take all the red coins.
So, if the sums of the red and blue coins are different, Alice can guarantee a win simply by choosing the set of coins with the higher total. If the red and blue coins have equal sums, Alice can at least guarantee a tie by arbitrarily choosing one set or the other.
Let’s call this strategy (taking either all the coins in even positions or all the coins in odd positions, whichever has the higher total) the “red/blue strategy”. This strategy constitutes a really elegant proof that Alice can never lose. But it’s not at all the end of the story—in particular, the red/blue strategy is not necessarily Alice’s best strategy! For example, consider this setup:
Notice that the “red” and “blue” coins have equal sums: . So if Alice just plays according to the red/blue strategy the result will be a tie. But Alice can do better: she should first take the 3, leaving Bob no choice but to take one of the 2s. But now there is a 1 and a 2 left, and Alice should obviously take the 2 (whereas the red/blue strategy would tell her to take the 1). So with best play Alice wins by a score of 5 to Bob’s 3.
This raises the natural question: when is a tie Alice’s best result? In other words, what sort of setups force a tie if both players play their best? Let’s call such setups “tied”.
As a first example, it is not hard to prove that symmetric games are tied. By a symmetric game I mean a game which stays the same when the order of the coins is reversed, i.e. where . For example,
Theorem. Symmetric games are tied.
Proof. Bob can force a tie by always playing on the opposite side from Alice: that is, if Alice takes then Bob takes , which has the same value by assumption. Since we already know that Alice will at least get a tie with best play, this must be the best result for both players (in particular, we know Bob cannot do any better with a different strategy).
However, this theorem does not completely characterize tied games. For example, the game
is also tied, even though it is not symmetric: each player will get 3 (if Alice starts by taking the 2, Bob takes the other 2, and then they split the 1s; if Alice starts by taking the 1, then it doesn’t matter what Bob takes next; on her next turn Alice will take a 2).
Can we completely characterize which games are tied? I will close by stating an observation, a theorem, and a few conjectures.
Observation. The empty game (consisting of zero coins) is tied, since after zero moves both players end with a value of zero. (This one is not really worth calling a theorem!)
Theorem. If is tied, then so is , the game obtained from by adding two copies of the coin , one on each end.
Proof. Bob can force a tie: after Alice takes one copy of , Bob takes the other one, and now the game is reduced to , which is tied by assumption.
Note that all symmetric games can be built up in this way, by starting with the empty game and successively adding “layers” that look like . So this observation and theorem together constitute an alternate, inductive proof that all symmetric games are tied.
If and are games (that is, sequences of an even number of coins), let denote the game obtained by concatenating the sequences of coins. For example, if and then .
Conjecture. If and are both tied, then so is .
For example, we know and are both tied since they are symmetric. This conjecture then claims that the game is tied as well (which happens to be true in this case, as you can check).
As a more interesting example, the foregoing theorem and conjecture (if true) could together be used to show that is tied (I’m tired of writing the commas in between single-digit coin values), because this game can be broken down as . And guess what, I have verified computationally that this game is indeed tied! (I’ll discuss how to do this in a future post.)
Conjecture. This completely characterizes tied games: a game is tied if and only if it is inductively built up, starting from the empty game, by applications of the foregoing theorem and conjecture.
I believe this conjecture less than I believe the first one. There might be other strange ways to build tied games.