Library · The Fiddler: Solutions · Chapter 153

Can You Escape the Infinite Loop?

Revised Report an error

Take a strip of paper 1010 inches long and 11 inch wide, give it a single half twist, and join the two short edges to make a Möbius strip. Draw a dot on the midline of the strip, half an inch from both edges. Distance on the strip is measured as an ant crawls: the shortest path along the paper, which may pass over an edge onto the other face. Some point or points of the strip are as far as possible from the dot. How far?

The Fiddler, Zach Wissner-Gross, July 7, 2023(original post)

The official solution appeared in the post of July 14, 2023 and gives 5.055.05 inches, attained at two points on the midline, and N=840N = 840 for the Extra Credit, with an average of 195/14195/14 faces. Both agree with the answers below.

Solution

The ant walks on the paper’s surface, so a spot on the front of the paper and the spot directly behind it on the back are different places, joined only by walking round an edge. The dot is drawn on the front.

Unrolling the surface. Shortest paths on a flat surface are straight lines once the surface is laid out flat, and this one can be laid out completely. Put the front face in the plane as the rectangle 0≤x≤100 \le x \le 10, −12≤y≤12-\tfrac12 \le y \le \tfrac12, with the dot at the origin. An ant walking over the top edge carries straight on, now on the back, and the back is a mirror image of the front across that edge, so it can be laid down as the next rectangle up, 12≤y≤32\tfrac12 \le y \le \tfrac32. Walking over the bottom edge works the same way, and so on, band after band. Walking 1010 inches along the strip brings the ant back to where it started on the paper, but the half twist has put it on the other face; that copy can be laid down as the next rectangle along. The whole plane is tiled by 10×110 \times 1 rectangles, and moving one rectangle across or one up switches the face.

The figure shows the result. The shaded rectangles are copies of the back, the white ones copies of the front.

The ant’s surface unrolled into the plane, front faces white and back faces shaded. Every black dot is a copy of the one dot. The copper point is as far as possible from all of them: the three copper paths each measure 5.05 inches.
The ant’s surface unrolled into the plane, front faces white and back faces shaded. Every black dot is a copy of the one dot. The copper point is as far as possible from all of them: the three copper paths each measure 5.055.05 inches.

Where are the copies of the dot? A copy lies at (10m,n)(10m, n) for whole numbers mm and nn, provided the rectangle there is a front face, that is, provided m+nm + n is even. Moving one rectangle along also mirrors the strip top to bottom, but the dot sits on the midline, so its mirror image is itself. A path the ant crawls unrolls into a path in the plane of the same length, from the spot it ends at to one copy of the dot, and the shortest such path is straight. So the ant’s distance from the dot to a spot is the straight-line distance from the spot to the nearest copy of the dot.

The largest empty circle. So the question becomes: which point of the plane is farthest from its nearest black dot? Such a point is the centre of the largest circle that has no black dots inside it. Look at the three copies O=(0,0)O = (0, 0), U=(10,1)U = (10, 1) and D=(10,−1)D = (10, -1). The point on the xx-axis equidistant from all three is at (c,0)(c, 0) with c2  =  (10−c)2+1,c^2 \;=\; (10 - c)^2 + 1, which simplifies to 20c=10120c = 101, so c=101/20=5.05c = 101/20 = 5.05. This is the centre of the circle through OO, UU and DD, and its radius is 5.055.05. No other copy is closer to it: the next nearest are (0,±2)(0, \pm 2), at a distance 5.052+4≈5.43\sqrt{5.05^2 + 4} \approx 5.43, and (20,0)(20, 0), at 14.9514.95.

To see that no point does better, notice that the plane is covered by triangles like OUDOUD and their mirror images, such as UU, DD, (20,0)(20, 0), all with corners at copies of the dot. Each triangle has all its angles below 90∘90^\circ, so the centre of its circumcircle lies inside it. The lines from that centre to the midpoints of the three sides cut the triangle into six right triangles, each with corners at one dot, the midpoint of a side through that dot, and the centre. All three corners are within 5.055.05 of that dot, and a disc contains every segment between its points, so the whole right triangle is too, with equality only at the centre. So every point of the plane is within 5.055.05 of a copy of the dot.  the farthest points are 5.05 inches from the dot. \boxed{\ \text{the farthest points are } 5.05 \text{ inches from the dot}. \ } There are two of them. The centre (5.05,0)(5.05, 0) is on the front, on the midline 5.055.05 inches along the strip; the centre of the mirror triangle, at (−5.05,0)(-5.05, 0), is on the back, on the midline, 5.055.05 inches the other way.

Three nearby guesses are each slightly wrong, which is what makes this puzzle treacherous. The point on the midline exactly halfway round is only 55 inches away. The two points on the edge halfway round are 52+0.52≈5.025\sqrt{5^2 + 0.5^2} \approx 5.025 inches away, since an ant can reach them along a straight line on the front. And on an untwisted ring the point opposite the dot on the inside would be 52+12≈5.099\sqrt{5^2 + 1^2} \approx 5.099 inches away, but the twist opens a second, shorter route to it.

The computation

The check does not unroll anything. It covers both faces of the paper with a grid of spacing 140\frac1{40} inch and lets the ant take short straight steps, with three rules for what happens when a step runs off the paper: over a long edge it lands on the other face, reflected; across the joined ends it lands on the other face with the strip turned over. Dijkstra’s shortest-path algorithm then finds the ant’s distance to every grid point. The steps run in 9696 directions, enough to follow straight lines closely, and they reproduce the paths in the figure exactly because (198,40)=38 (5,1)+2 (4,1)(198, 40) = 38\,(5,1) + 2\,(4,1).

import heapq
from math import gcd, hypot

# The strip is 10 by 1 in paper coordinates (x, y), with two
# faces, f = 0 (front) and f = 1 (back), on a grid of spacing
# 1/40. A step is a short straight move (di, dj) in grid units;
# land() says where it ends when it runs off the paper.
n = 40
X, Y = 10*n, n               # x in 0..X-1 (wraps), y in 0..Y

def land(i, j, f, di, dj):
    i, j = i + di, j + dj
    if j < 0:                # over the edge y = 0
        j, f = -j, 1 - f
    elif j > Y:              # over the edge y = 1
        j, f = 2*Y - j, 1 - f
    if i >= X or i < 0:      # across the join: the half twist
        i, j, f = i % X, Y - j, 1 - f    # flips y and face
    return i, j, f

steps = [(a, b) for a in range(-6, 7) for b in range(-6, 7)
         if (a, b) != (0, 0) and gcd(abs(a), abs(b)) == 1]

start = (0, Y//2, 0)         # the dot: midline, front face
dist = {start: 0.0}
heap = [(0.0, start)]
while heap:
    d, (i, j, f) = heapq.heappop(heap)
    if d > dist[(i, j, f)]:
        continue
    for a, b in steps:
        nxt = land(i, j, f, a, b)
        nd = d + hypot(a, b)/n
        if nd < dist.get(nxt, float("inf")):
            dist[nxt] = nd
            heapq.heappush(heap, (nd, nxt))

top = max(dist.values())
for (i, j, f), d in sorted(dist.items()):
    if d > top - 1e-9:
        print(f"farthest: x = {i/n:.3f}, y = {j/n:.3f}, "
              f"face {f}, distance {d:.4f}")

It prints

farthest: x = 4.950, y = 0.500, face 1, distance 5.0500
farthest: x = 5.050, y = 0.500, face 0, distance 5.0500

These are the two points found above: on the front 5.055.05 inches along, and on the back at x=4.95x = 4.95, which is 5.055.05 inches back the other way.

Extra Credit

Now take a prism whose ends are regular NN-gons, twist it by a random whole number of NNths of a turn (from one up to NN, all equally likely), bend it into a loop and join the ends. For a square prism the twists of one, two, three and four quarters give 11, 22, 11 and 44 distinct faces, an average of 22. For which N≤1000N \le 1000 is the average number of distinct faces largest?

Solution

Number the prism’s side faces 0,1,…,N−10, 1, \dots, N - 1 around the prism. Joining the ends with a twist of kk steps glues the end of face ii to the start of face i+ki + k, counting modulo NN. Following a single face round the loop over and over, you pass through faces ii, i+ki + k, i+2ki + 2k, and so on, and all of these are one face of the finished solid. Face jj is reached from face ii exactly when j−ij - i is a multiple of kk modulo NN, and the multiples of kk modulo NN are exactly the multiples of g=gcd⁡(k,N)g = \gcd(k, N). So the faces fall into gg classes, and the twisted prism has gcd⁡(k,N)\gcd(k, N) distinct faces. The square prism’s 1,2,1,41, 2, 1, 4 are gcd⁡(1,4),gcd⁡(2,4),gcd⁡(3,4),gcd⁡(4,4)\gcd(1,4), \gcd(2,4), \gcd(3,4), \gcd(4,4).

The average over the NN twists is f(N)  =  1N∑k=1Ngcd⁡(k,N).f(N) \;=\; \frac1N \sum_{k=1}^{N} \gcd(k, N). It has a tidy form. For each divisor dd of NN, the values of kk with gcd⁡(k,N)=d\gcd(k, N) = d are dd times the numbers from 11 to N/dN/d that share no factor with N/dN/d, and there are φ(N/d)\varphi(N/d) of those, where φ\varphi is Euler’s totient function. So f(N)  =  ∑d∣Nd φ(N/d)N  =  ∑e∣Nφ(e)e,f(N) \;=\; \sum_{d \mid N} \frac{d\,\varphi(N/d)}{N} \;=\; \sum_{e \mid N} \frac{\varphi(e)}{e}, writing e=N/de = N/d. The last sum is multiplicative: it splits into a product over the prime powers in NN. For a prime power, the divisors are 1,p,…,pa1, p, \dots, p^a and each φ(pj)/pj\varphi(p^j)/p^j with j≥1j \ge 1 equals 1−1/p1 - 1/p, so f(pa)  =  1+a(1−1p),f(N)  =  ∏pa ∥ N(1+a(1−1p)),f(p^a) \;=\; 1 + a\Bigl(1 - \frac1p\Bigr), \qquad f(N) \;=\; \prod_{p^a \,\|\, N} \Bigl(1 + a\Bigl(1 - \frac1p\Bigr)\Bigr), where pa ∥ Np^a \,\|\, N means pap^a is the exact power of pp dividing NN.

Each prime contributes a factor between 1.51.5 and 22 for its first power, and each further power adds less than 11 to that factor while multiplying the cost by pp. So the winners are numbers built from many small primes, with small exponents. The search over N≤1000N \le 1000 (below) settles it: the best is 840=23⋅3⋅5⋅7840 = 2^3 \cdot 3 \cdot 5 \cdot 7, with f(840)  =  (1+32)(1+23)(1+45)(1+67)  =  52⋅53⋅95⋅137  =  19514.f(840) \;=\; \Bigl(1 + \tfrac32\Bigr)\Bigl(1 + \tfrac23\Bigr) \Bigl(1 + \tfrac45\Bigr)\Bigl(1 + \tfrac67\Bigr) \;=\; \frac52\cdot\frac53\cdot\frac95\cdot\frac{13}{7} \;=\; \frac{195}{14}.  N=840, averaging 19514≈13.93 distinct faces. \boxed{\ N = 840, \text{ averaging } \tfrac{195}{14} \approx 13.93 \text{ distinct faces}. \ } The runners-up are well behind: 720=24⋅32⋅5720 = 2^4 \cdot 3^2 \cdot 5 averages 12.612.6 and 900=22⋅32⋅52900 = 2^2 \cdot 3^2 \cdot 5^2 averages 12.1312.13. Adding the prime 77 to 120120 multiplies the average by 13/713/7, almost doubling it, which no alternative within 10001000 can match.

The computation

The check glues the faces directly. For each twist it joins face ii to face i+ki + k with a union–find structure and counts the classes, confirms the square prism’s 1,2,1,41, 2, 1, 4, and confirms that the count equals gcd⁡(k,N)\gcd(k, N) for every twist of every prism up to N=60N = 60. It then averages the face counts for every NN up to 10001000 and lists the three best.

from fractions import Fraction

def distinct_faces(N, k):
    """Join an N-gon prism's ends with a twist of k/N of a
    turn and count the faces. Once round the loop, side face
    i runs on into side face i + k (mod N)."""
    parent = list(range(N))
    def root(a):
        while parent[a] != a:
            a = parent[a]
        return a
    for i in range(N):
        parent[root(i)] = root((i + k) % N)
    return len({root(i) for i in range(N)})

square = [distinct_faces(4, k) for k in (1, 2, 3, 4)]
assert square == [1, 2, 1, 4]
assert all(distinct_faces(N, k) == gcd(k, N)
           for N in range(1, 61) for k in range(1, N + 1))
print("faces = gcd(k, N) for every prism up to N = 60")

avg = {N: Fraction(sum(gcd(k, N) for k in range(1, N + 1)), N)
       for N in range(1, 1001)}
for N in sorted(avg, key=avg.get, reverse=True)[:3]:
    print(f"N = {N}: average {avg[N]} = {float(avg[N]):.4f}")

It prints

faces = gcd(k, N) for every prism up to N = 60
N = 840: average 195/14 = 13.9286
N = 720: average 63/5 = 12.6000
N = 900: average 182/15 = 12.1333
Report an error on this page

Reports are stored by Netlify. See the privacy note.