Chapter 26
World Cup Standings and Number Shuffling
Riddler Express
In the World Cup group stage, a group of four teams plays a round robin: every team plays the other three once. A win is worth points, a draw point, and a loss points. For a given group, how many different final standings, including point totals, are possible?
The Riddler, FiveThirtyEight, March 23, 2018(original post)
Solution
Read the question carefully. A "final standing including point totals" is an assignment of a point total to each of the four named teams, so the answer is the count of distinct -tuples over all possible round-robin outcomes, not the count of unordered point multisets. Two different game-by-game outcomes can yield the same tuple, so the answer is below the naive .
Why the naive count is . Six games are played (each pair plays once), and each game has three outcomes: team wins, draw, or team wins. So there are game-by-game outcomes, each of which determines a point tuple.
Why overcounts. Several distinct game-outcome assignments produce the same point tuple. The cleanest example is a -cycle: if beats , beats , beats , every team in the cycle gains and loses , just as if the wins ran the other way ( beats , beats , beats ). Holding the three games involving fixed, those two outcomes give the same . There are also less obvious coincidences (for example, replacing two wins by two draws keeps a team’s total at wait, vs , not equal; cancellations are rarer than the -cycle case but exist for -team configurations).
Direct count. The cleanest path is direct enumeration. Run through all assignments, compute the point tuple, and take the cardinality of the resulting set. The answer is
Reconciliation with the official’s bookkeeping. The official write-up reaches by listing every unordered point multiset that can occur, counting (a) the number of distinct game-outcome constructions producing each multiset and (b) the number of permutations of the multiset over the four teams. For multisets such as the six constructions all give the single tuple , so the construction redundancy is . Summing redundancies across all multisets yields duplicates, and . Direct enumeration confirms.
The computation
Brute-force every round-robin outcome and count distinct point tuples.
List the six unordered pairs of teams.
Loop over the outcome assignments; for each, accumulate points.
Collect the resulting point tuples in a set and report its size.
from itertools import product
games = [(0,1), (0,2), (0,3), (1,2), (1,3), (2,3)]
standings = set()
for outcome in product(range(3), repeat=6):
pts = [0, 0, 0, 0]
for (i, j), o in zip(games, outcome):
if o == 0: pts[i] += 3 # i wins
elif o == 1: pts[i] += 1; pts[j] += 1 # draw
else: pts[j] += 3 # j wins
standings.add(tuple(pts))
print("distinct (P_A, P_B, P_C, P_D) tuples:", len(standings))
The script prints .
Riddler Classic
Take a positive integer and move its last digit to the front. For example, becomes . What is the smallest positive integer such that this operation yields exactly twice the original?
The Riddler, FiveThirtyEight, March 23, 2018(original post)
Solution
Write the mystery number as , where is its last digit and is the block of digits in front. Moving the last digit to the front puts in the place, giving , and we want this to equal : The right side is a multiple of , and since is a single digit not divisible by , the factor must be. So we need , and the smallest valid is the one with the smallest such .
The powers of modulo cycle with period , running . The value first appears at . Then , and must itself have exactly digits. Taking gives only a -digit (a leading zero, not allowed), so the smallest valid digit is , giving and Indeed , which is with its final moved to the front.
The computation
Find the smallest with , build the number from , and check directly that moving its last digit to the front doubles it.
n = 1
while pow(10, n, 19) != 2:
n += 1
b = (10**n - 2) // 19 * 2 # a = 2
N = 10 * b + 2
rotated = int(str(N % 10) + str(N // 10)) # last digit to the front
print(n, N, rotated == 2 * N) # 17, 105263157894736842, True