Skip to content
Vamshi Jandhyala

Books · The Fiddler: Solutions

Chapter 38

Can You Box the Letters?

A square has eight points on it, labelled A through H, two on each side. A “letter boxed” sequence visits all eight points, with the rule that two consecutive points in the sequence are never on the same side. (For example AFBCHEDG is valid, while AFBCHGED is not, since H and G share a side.) How many distinct valid sequences use all eight points?

The Fiddler, Zach Wissner-Gross, September 12, 2025(original post)

Eight points, two per side. The dashed path is the valid example AFBCHEDG.

Solution

Treat each side as a colour, so we are arranging four colours, each appearing twice, with no two equal colours adjacent, and then distinguishing the two points of each colour. The number of colour-patterns with no equal neighbours is, by inclusion–exclusion on which colours are glued together, k=04(1)k(4k)(8k)!24k=25202520+1080240+24=864.\sum_{k=0}^{4}(-1)^k\binom4k\frac{(8-k)!}{2^{\,4-k}} =2520-2520+1080-240+24=864. Each side’s two points are distinct and can be ordered in 2!2! ways, contributing (2!)4=16(2!)^4=16: 864×16=13,824.864\times16=\boxed{13{,}824}.

The computation

With only eight points the whole thing is small enough to count head-on: run through all 8!8! orderings and keep those in which no two consecutive points share a side.

from itertools import permutations
side = dict(zip('ABCDEFGH', [0, 0, 1, 1, 2, 2, 3, 3]))     # two points per side
cnt = sum(all(side[s[i]] != side[s[i+1]] for i in range(7))
          for s in permutations('ABCDEFGH'))
print(cnt)                               # 13824

Extra Credit

Now the square has twelve points, A through L, three on each side, with the same rule. How many valid sequences use all twelve?

Solution

Arrange four colours, each appearing three times, with no two equal adjacent, then order the three points on each side in 3!3! ways. Counting the no-equal-neighbour colour patterns and multiplying by (3!)4=1296(3!)^4=1296 gives 41,304×1296=53,529,984.41{,}304\times1296=\boxed{53{,}529{,}984}. (The source’s count is paywalled; this is my own enumeration.)

The computation

Twelve points make 12!12! too many to sweep, but the side-pattern is just the distinct arrangements of four colours three-apiece (only 369,600369{,}600). Count those with no equal neighbours, then multiply by the (3!)4(3!)^4 orderings of each side’s three points.

from sympy.utilities.iterables import multiset_permutations
from math import factorial
pat = sum(all(p[i] != p[i+1] for i in range(11))
          for p in multiset_permutations('AAABBBCCCDDD'))
print(pat, pat * factorial(3)**4)        # 41304  53529984