Superfluous letters
Increpare (i.e., Stephen Lavelle), creator of Stephen’s Sausage Roll, has an interesting new short game, Superfluous letters, apparently the result of a serendipitous misunderstanding. It’s sort of a twist on Lights-Out: there are 26 letters drawn in 5x3 grids, and the goal is to find combinations of letters that xor together to any of the other letters. Every time you find such a combination, the found letter is disabled and you get a point. What’s the maximum score you can get?
In this post, I’ll describe a polynomial time algorithm to solve the game.
If you haven’t played with the game yet, though, please, go and futz with it for a while first! Here’s a link again: Superfluous letters.
1. Solving the game
Ok, now that you are back, you probably found some formulae, like . If the game didn’t immediately disable the , there’d also be the formula (blank), which you can get by adding (xoring) to both sides. For a similar reason, we can get associated formulae , , and for all the other letters appearing in the formula. But, because letters are disabled, once you use the formula in any of its forms, it is worn out.
Now, what about ? If we use , then we can’t use anymore to create . At first glance, this seems like it might be the big issue for solving the game, that you’ll have to search for an order to execute formulae in. However, we can substitute the equation for into the one for : . So, the order we create letters actually doesn’t matter!
Now, let’s say we have a run-through of the game, and that at some point we used the equation . A surprising thing is that we can instead use, say, and replace all of the ’s after that point with . If we also end up creating and , we might have to substitute other formulae for those letters. But, in any case, we can transform the run-through into one where we create instead of at that step. The takeaway here is that a run-through can be described as a sequence of sets of letters that sum to blank, so long as we aren’t picky about remembering exactly which letters we create along the way. Importantly, the score you’d get from the run-through doesn’t change.[1]
Let be the collection of subsets of letters that sum to blank, including the empty set. For instance, is an element of . A run-through gives some sequence , and the max score question is about how big can be.
The idea is going to be that there is a meta Lights-Out game going on with the formulae themselves. I’m not sure how to talk about this without actually invoking some linear algebra, but here are a few facts about .
- We can use symmetric difference (xor for sets) as an addition-like operation on . As an example, we define , the set of letters that are in exactly one of the two sets. This is supposed to correspond to the substitution operation we applied to a formula with a disabled letter.
- is a finite set, so there is a minimal set that generates all of (that is, every element of is a sum of some of the ).
- No matter how you find a minimal generating set, will always be the same number. This is known as the dimension of . (This takes a little work to prove, but it is a standard result of linear algebra.)
- None of the elements of a minimal generating set is a sum of any of the others. For instance, if , then we can remove from the generating set to get an even smaller generating set.
Consider a run-through . The first observation is that this must be a generating set for , since if there is some in that’s not generated by them, we can append to the run-through. Likely, we’ll have to eliminate a bunch of letters from that the run-through has disabled so far, but this is not a problem: since is not generated by , the version of after elimination will not be empty, and since in addition no letter is completely blank, it will contain at least two letters.
The second observation is that in a maximal run-through, is a minimal generating set for . If one of the sets were a sum of earlier sets, for example if , then since creates a letter that is not present for any of the future formulae, that letter would have to be used in , too, which is impossible. In general, if any of the sets is a sum of the other sets, then by rearranging the equation we get a set that’s a sum of earlier sets.
Theorem. Every maximal run-through has the same length, the dimension of .
Anyway, this means that if we have any minimal generating set , we can use elimination to get a sequence of moves from it, and with it we’ll achieve the maximum score.
2. The algorithm
Getting a generating set for quickly needs some acquaintance with linear algebra. If you are happy with waiting for your computer, though, this will do:
- let start as an empty subset of .
for every subset of letters:
- check if the letters in xor to blank. if they don’t, continue with the next .
- check if is already a sum of sets from . if it is, continue with the next .
- put into
- now is a minimal generating set.
Let be a matrix of ’s and ’s where each column corresponds to the pixels of a different letter. An element of corresponds to a 26-element vector of ’s and ’s with if and only if the th letter is in , which means this vector satisfies . That is, corresponds to the nullspace of .
In Mathematica, gives a minimal generating set for the nullspace, given as a matrix with one generator per row. The algorithm is with the maximum dimension of the matrix .
Then, we can convert this minimal generating set into a list of moves by (1) always choosing the first letter in a given set and (2) eliminating that letter from the remaining sets. This happens to be known as Gaussian elimination, or row reduction. Mathematica also happens to have this function built-in, so this is the complete algorithm for solving the game:
with the understanding that we read off the rows of the result to get a run-through.It doesn’t give a speed run, but the program does run quickly. Here’s a solution it came up with:
giving a score of .3. Some analysis
The dimension of is the dimension of the nullspace of , and the dimension of a nullspace is , where the rank of is a minimal generating set for the pictures of the letters themselves. There are 15 pixels, and this particular set of letters ends up fully exercising all the pixels. Mathematica agrees: the rank of is 15. To complete the numerology, , the maximal score. (Put a dual way, we have a system of equations corresponding to each pixel and of variables corresponding to each letter. Each equation, if it is not superfluous, decreases the degrees of freedom by one. So, is a priori a lower bound for the maximal score.)
If the pictures had been less independent of each other, then the maximal score could have been larger.
What if Stephen were monkeys at color pickers, and the letters were completely random? What are the chances that we would be in this universe where the maximal score is only ?
There is a recurrence describing the probability that a matrix has rank .
This comes from realizing that we can always assume that the first columns have been row-reduced through a change-of-basis, and change of basis does not affect the distribution.The value of is approximately . So, fairly likely for the maximum score to be . In fact, the expected value of the maximum score is just .
(An interesting fact while we are here: the limit of as is not as it is over . Modulo , it comes out to ! Maybe it seems more reasonable if we realize this is the same as saying that the determinant of a square matrix of all ’s and ’s is odd about a quarter of the time. The expected rank of the matrix is pretty high though, about .)
A consequence of the rank being and there being pixels is that you can draw anything.
A strange property about the letters as designed is that every letter can be drawn using the other letters. In linear algebra language, this is saying that if you remove any single letter, you can still draw the rest. For a given letter, the probability that you can still draw everything in a monkey-drawn alphabet is . I wasn’t able to work out the inclusion-exclusion for the probability that every letter has this property, but I’d expect it to be rather high.