Library · The Fiddler: Solutions · Chapter 143

Can You Shape the Peloton?

Revised Report an error

A peloton of cyclists rides in rows. Its shape can be a triangle, a rhombus, or something in between: rows of 1,2,3,…1, 2, 3, \dots riders widening to a widest row, then narrowing again by one rider per row, but stopping anywhere from straight after the widest row (a triangle) to a final single rider (a rhombus). With a widest row of four riders there are four such formations, shown below.

The four formations whose widest row has four riders, from the triangle to the rhombus.
The four formations whose widest row has four riders, from the triangle to the rhombus.

Some numbers of riders allow more than one formation. With 1515 riders there are two: a triangle five riders wide, and a rhombus four riders wide missing its bottom rider. After 1515, what is the next number of riders with two distinct formations?

The Fiddler, Zach Wissner-Gross, September 22, 2023(original post)

The official solution appeared in the post of September 29, 2023 and gives 3636 for the main puzzle and 141141 for the Extra Credit. Both agree with the answers below.

Solution

First, count the riders in a formation. Write aa for the width of the widest row. A full rhombus has rows 1,2,…,a,…,2,11, 2, \dots, a, \dots, 2, 1, and it holds a2a^2 riders: it is a square of side aa squashed sideways, and indeed a+2(1+2+⋯+(a−1))=a+a(a−1)=a2a + 2(1 + 2 + \dots + (a - 1)) = a + a(a - 1) = a^2. Every other formation is this rhombus with its bottom rows removed, and the removed rows, b,b−1,…,1b, b - 1, \dots, 1, form a triangle holding the triangular number Tb=1+2+⋯+b=12b(b+1)T_b = 1 + 2 + \dots + b = \tfrac12 b(b + 1). So a formation has N  =  a2−Tb riders,0≤b≤a−1,N \;=\; a^2 - T_b \text{ riders}, \qquad 0 \le b \le a - 1 , with b=0b = 0 the rhombus and b=a−1b = a - 1 the triangle, which holds TaT_a riders.

So the formations with a widest row of aa give the numbers from TaT_a up to a2a^2, spaced by triangular numbers below a2a^2. Listing them row by row:

widest row aa riders a2−Tba^2 - T_b for b=a−1,…,1,0b = a - 1, \dots, 1, 0
11 11
22 3, 43,\ 4
33 6, 8, 96,\ 8,\ 9
44 10, 13, 15, 1610,\ 13,\ 15,\ 16
55 15, 19, 22, 24, 2515,\ 19,\ 22,\ 24,\ 25
66 21, 26, 30, 33, 35, 3621,\ 26,\ 30,\ 33,\ 35,\ 36
77 28, 34, 39, 43, 46, 48, 4928,\ 34,\ 39,\ 43,\ 46,\ 48,\ 49
88 36, 43, 49, 54, 58, 61, 63, 6436,\ 43,\ 49,\ 54,\ 58,\ 61,\ 63,\ 64

This table is complete for every count up to 3636, because a formation with widest row aa has at least TaT_a riders, and T9=45T_9 = 45. So the formations for any number up to 3636 all appear above. Reading the counts above 1515 in order, 16,19,21,22,24,25,26,28,30,33,34,3516, 19, 21, 22, 24, 25, 26, 28, 30, 33, 34, 35 each appear once, and the next count, 3636, appears twice: as the triangle eight wide and as the rhombus six wide.  36 riders. \boxed{\ 36 \text{ riders}. \ } That 3636 is both a square and a triangular number is exactly what makes it work here. The next two counts with two formations, 4343 and 4949, are visible in the table too.

The two formations of 36 riders: a triangle eight wide and a rhombus six wide.
The two formations of 3636 riders: a triangle eight wide and a rhombus six wide.

The computation

The program builds every formation up to a widest row of 3030 riders, row by row exactly as described in the puzzle, counts its riders, and groups the formations by count. A formation with widest row aa has at least 1+2+⋯+a1 + 2 + \dots + a riders, so every count up to 1+2+⋯+30=4651 + 2 + \dots + 30 = 465 has all its formations in the list, and the search only looks there.

from collections import defaultdict

W = 30                 # widest formation built
shapes = defaultdict(list)
for a in range(1, W + 1):          # widest row
    for b in range(a):             # bottom rows removed
        rows = [*range(1, a + 1), *range(a - 1, b, -1)]
        shapes[sum(rows)].append(rows)

# Every formation has at least 1+2+...+a riders, so any count
# up to 1+2+...+W is covered by widths at most W: complete.
limit = W * (W + 1) // 2
def smallest(k, above=0):
    return min(n for n, f in shapes.items()
               if above < n <= limit and len(f) >= k)

print("main:", smallest(2, above=15))

It prints

main: 36

Extra Credit

What is the fewest number of riders with three distinct formations?

Solution

Turn the formula around. A count NN has a formation with widest row aa exactly when a2−Na^2 - N is a triangular number TbT_b with b≤a−1b \le a - 1, and that last condition holds exactly when N≥TaN \ge T_a. So to list the formations of NN, run through the squares a2a^2 from the first one at least NN, stop when TaT_a passes NN, and keep each aa for which the gap a2−Na^2 - N is triangular.

For N=141N = 141 the candidates are a=12a = 12 to 1616, since 122=14412^2 = 144 is the first square past 141141 and T17=153T_{17} = 153 is too big:

aa a2−141a^2 - 141 triangular?
1212 33 T2T_2
1313 2828 T7T_7
1414 5555 T10T_{10}
1515 8484 no (T12=78T_{12} = 78, T13=91T_{13} = 91)
1616 115115 no (T14=105T_{14} = 105, T15=120T_{15} = 120)

So 141141 has three formations, none of them a triangle or a rhombus.

The three formations of 141 riders, with widest rows of 12 , 13 and 14 .
The three formations of 141141 riders, with widest rows of 1212, 1313 and 1414.

That no smaller count has three is a matter of checking each count below 141141 the same way, and there is no shortcut that avoids it: the counts with two formations are scattered irregularly (15,36,43,49,64,66,78,…15, 36, 43, 49, 64, 66, 78, \dots). The exhaustive check is the computation below. Its verdict is  141 riders. \boxed{\ 141 \text{ riders}. \ }

The computation

The list of formations from The computation above already settles it: ask for the smallest count with at least three formations, and print their widest and last rows.

n = smallest(3)
print("extra credit:", n)
for rows in shapes[n]:
    print(f"  widest row {max(rows)}, last row {rows[-1]}")

It prints

extra credit: 141
  widest row 12, last row 3
  widest row 13, last row 8
  widest row 14, last row 11
Report an error on this page

Reports are stored by Netlify. See the privacy note.