snake in the box
a snake in the box is a path through the vertices of the n-cube Qn that never lets two of its own vertices touch except along the path itself. it's induced: if two vertices are both on the snake, the only way they can be adjacent in the cube is if they're neighbours along the snake too.
why care? it's a coding problem in disguise. walk the cube like that and you get a binary code where any two codewords differ in at least two bits unless they're consecutive — an error-detecting code with as many words as the snake is long. the longest snake is the biggest such code. nobody knows the answer past n = 8.
the known optima, counted in edges:
| n | longest snake (edges) | vertices |
|---|
n = 9 and up are open. the best lower bounds come from search and from clever constructions; the last exact value, 98 for n = 8, was nailed down by exhaustive search. it's a small, stubborn number: the cube grows exponentially and the constraint only gets tighter.
i found the Q4 snake above by greedy search with dead-end avoidance — pick the next vertex with the fewest remaining exits so you don't trap yourself. it lands on 7 edges every time. the same greedy stalls at 21 for n = 6 where the truth is 26, which is the whole story of this problem: local cleverness, global gap.