Skip to content
Vamshi Jandhyala

Books · The Riddler

Chapter 173

Picture Frames That Crash To The Floor

Riddler Express

Imagine a framed picture suspended by a cord that hangs on two nails. If the picture were hung normally, you would expect the removal of one nail to leave it hanging on the other. How can you hang a picture on two nails so that if you remove either nail the picture crashes to the floor?

The Riddler, FiveThirtyEight, February 9, 2018(original post)

Solution

The idea. Each time the cord passes a nail, record an xix_i if it goes clockwise around nail ii and xi1x_i^{-1} if counter-clockwise. Reading along the cord from one end to the other produces a word in the symbols x1,x11,x2,x21,x_1, x_1^{-1}, x_2, x_2^{-1}, \ldots. The picture stays up on a given subset SS of the nails present if and only if that word is the empty word in the free group generated by {xi:iS}\{x_i : i \in S\}, i.e. once you erase every xj±1x_j^{\pm 1} for jSj \notin S and cancel adjacent inverses, nothing should remain.

So the Express asks: find a word ww in x1,x2x_1, x_2 such that w1w \ne 1 in the free group on {x1,x2}\{x_1, x_2\} (so the picture stays up when both nails are present), but w=1w = 1 once either generator is set equal to the identity.

The construction. The commutator w=x1x2x11x21w = x_1 x_2 x_1^{-1} x_2^{-1} does the job. Erase x1x_1 and the word becomes x2x21x_2 x_2^{-1}, which cancels to the empty word, so removing nail 11 drops the picture. Erase x2x_2 and the word becomes x1x11x_1 x_1^{-1}, which again cancels. And ww is not the identity in the free group on {x1,x2}\{x_1, x_2\} (it is the standard generator of the commutator subgroup), so with both nails in place the cord cannot be pulled free.

The computation

Treat a hanging recipe as a list of pairs (i,±1)(i, \pm 1) read along the cord. Free-group reduction is just a stack: walk the word, push each letter, and pop whenever the top two are mutual inverses. The picture stays up on subset SS iff the reduced word over SS is empty. Check that the commutator w=x1x2x11x21w = x_1 x_2 x_1^{-1} x_2^{-1} reduces to nothing when either generator is removed and survives reduction when both are present.

  1. Implement free-group reduction as a one-pass stack.

  2. Apply it to ww restricted to the surviving generator set.

  3. Check w1w \ne 1 on {1,2}\{1,2\} and w=1w = 1 on {2}\{2\} and {1}\{1\}.

def reduce(word):
    stack = []
    for g, s in word:
        if stack and stack[-1] == (g, -s):
            stack.pop()
        else:
            stack.append((g, s))
    return stack

def restrict(word, keep):
    return reduce([(g, s) for g, s in word if g in keep])

w = [(1, 1), (2, 1), (1, -1), (2, -1)]            # x1 x2 x1^-1 x2^-1
print('both:   ', restrict(w, {1, 2}))            # nonempty
print('nail 1: ', restrict(w, {2}))               # []
print('nail 2: ', restrict(w, {1}))               # []

The script prints the full word for the “both” case (nontrivial), and [] for both single-nail restrictions: the picture is hanging when both nails are present and falls when either is removed.

Riddler Classic

What about three nails? What about four nails? What about on two red nails and two blue nails such that the picture falls if both red nails are removed and if both blue nails are removed but remains hanging if one of each colour is removed?

The Riddler, FiveThirtyEight, February 9, 2018(original post)

Solution

The pattern. Write [a,b]=aba1b1[a, b] = a b a^{-1} b^{-1} for the commutator of two words. The Express used [x1,x2][x_1, x_2] to enforce “both nails needed.” Iterating this construction yields a hanging recipe for any number of nails. The key fact: in the free group on x1,,xnx_1, \ldots, x_n, the commutator [u,v][u, v] is trivial whenever either uu or vv is trivial, but is nontrivial whenever both uu and vv are nontrivial. So if uu is a hanging recipe for the first n1n - 1 nails (falls when any one of them is removed, survives when all are present), then [u,xn]=uxnu1xn1[u, x_n] = u x_n u^{-1} x_n^{-1} is a hanging recipe for nn nails.

Three nails. Start with the Express word u=[x1,x2]u = [x_1, x_2], then form [[x1,x2],x3]=ux3u1x31=x1x2x11x21x3x2x1x21x11x31,[[x_1, x_2], x_3] = u x_3 u^{-1} x_3^{-1} = x_1 x_2 x_1^{-1} x_2^{-1} x_3 x_2 x_1 x_2^{-1} x_1^{-1} x_3^{-1}, a word of length 1010. Removing nail 33 kills the two x3x_3 letters and leaves uu1=1u u^{-1} = 1. Removing nail 11 leaves ux2x21=1u \to x_2 x_2^{-1} = 1, so the whole word reduces to 1x31x31=11 \cdot x_3 \cdot 1 \cdot x_3^{-1} = 1. Same for nail 22. With all three nails in place, no further cancellation is possible and the word is nontrivial.

Four nails. The same idea, one step deeper. Setting v=[x3,x4]v = [x_3, x_4] in parallel and forming [[x1,x2],[x3,x4]][\,[x_1, x_2],\, [x_3, x_4]\,] gives a balanced length-1616 word. Removing any one of the four nails kills its bracketed factor (turning uu or vv into 11), and the outer commutator then collapses to 11.

Two red, two blue. The red/blue puzzle wants the picture to fall iff both reds are removed or both blues are removed, but to stay up if one of each is removed. Let reds be nails 1,21, 2 and blues be nails 3,43, 4. Form the commutator of the products w=[x1x2,x3x4]=x1x2x3x4(x1x2)1(x3x4)1=x1x2x3x4x21x11x41x31,\begin{aligned} w = [x_1 x_2,\, x_3 x_4] &= x_1 x_2 \cdot x_3 x_4 \cdot (x_1 x_2)^{-1} \cdot (x_3 x_4)^{-1} \\ &= x_1 x_2 x_3 x_4 x_2^{-1} x_1^{-1} x_4^{-1} x_3^{-1}, \end{aligned} a word of length 88. Removing both reds (kill x1x_1 and x2x_2): the first factor x1x2x_1 x_2 collapses to 11, and the commutator [1,x3x4]=1[1, x_3 x_4] = 1. Same with both blues. Removing one of each: say nails 11 and 33 are kept (so x2,x4x_2, x_4 erased). The word becomes x1x3x11x31=[x1,x3],x_1 x_3 x_1^{-1} x_3^{-1} = [x_1, x_3], the Express commutator on the surviving generators, which is nontrivial. The four “one of each” cases all yield a [xi,xj][x_i, x_j]-shaped commutator on the survivors.

The computation

Re-use the free-group reducer of The computation above. For each candidate word, take every subset of generators corresponding to a “nails present” state and reduce; verify the word is empty exactly when the puzzle says the picture should fall.

  1. Build the four candidate words (three-nail iterated commutator, four-nail nested commutator, two-red-two-blue commutator).

  2. For each, walk over all 2n2^n subsets of the nn nails.

  3. Check the reduced restriction is empty iff the corresponding subset of nails is removed in the puzzle’s prescription.

def reduce(word):
    stack = []
    for g, s in word:
        if stack and stack[-1] == (g, -s):
            stack.pop()
        else:
            stack.append((g, s))
    return stack

def restrict(word, keep):
    return reduce([(g, s) for g, s in word if g in keep])

def inv(word):
    return [(g, -s) for g, s in reversed(word)]

def commutator(a, b):
    return a + b + inv(a) + inv(b)

x = {i: [(i, 1)] for i in (1, 2, 3, 4)}

# Three nails: [[x1, x2], x3]
w3 = commutator(commutator(x[1], x[2]), x[3])
print('3-nail length', len(w3))
for nails in [{1,2,3}, {2,3}, {1,3}, {1,2}]:
    print('  keep', nails, '->', restrict(w3, nails))

# Four nails: [[x1, x2], [x3, x4]]
w4 = commutator(commutator(x[1], x[2]), commutator(x[3], x[4]))
print('4-nail length', len(w4))
for nails in [{1,2,3,4}, {2,3,4}, {1,3,4}, {1,2,4}, {1,2,3}]:
    print('  keep', nails, '->', len(restrict(w4, nails)))

# Red/blue: [x1 x2, x3 x4], reds = {1,2}, blues = {3,4}
wrb = commutator(x[1] + x[2], x[3] + x[4])
print('red/blue length', len(wrb))
for nails in [{3,4}, {1,2}, {1,3}, {1,4}, {2,3}, {2,4}, {1,2,3,4}]:
    print('  keep', nails, '->', restrict(wrb, nails))

The script prints, in summary: w3w_3 has length 1010 and reduces to the empty word when any one of nails 1,2,31, 2, 3 is removed; w4w_4 has length 1616 and reduces to the empty word when any one of nails 1,2,3,41, 2, 3, 4 is removed; wrbw_{\mathrm{rb}} has length 88 and reduces to the empty word when nails {1,2}\{1,2\} or {3,4}\{3,4\} are removed, but stays nontrivial for each of the four “one red, one blue” removals. All three cases match the boxed answer.