# Riddler Express 2022-12-09

2022 FIFA World Cup – Can You Win The Riddler Football Playoff?

Ryan McShane https://ryanmcshane.com
2022-12-10

### The question from fivethirtyeight.com:

World Cup group play consists of eight groups, each with four teams. The four teams in a group all play each other once (for a total of six matches), earning three points for a win, one point for a draw and zero points for a loss.

After group play in a particular group, all four teams have different numbers of points. The first-place team has $$A$$ points, the second-place team $$B$$ points, the third place team $$C$$ points and the last-place team $$D$$ points. Find all possible quadruples $$(A, B, C, D)$$.

## Enumeration and Calculations done in R

expand.grid does the heavy lifting here. We give it a vector of $$(3, 1, 0)$$, tell it there are six matches, and it finds all of the combinations. From there, we get group scores for teams $$X_1, X_2, X_3, \text{ and } X_4$$, sort them into quadruples $$(A, B, C, D)$$, and find the unique ones (there are 40).

## Function that determines the RHS's score depending on LHS team
rhs = function(x){
y = case_when(x == 3 ~ 0L, x == 1 ~ 1L, x == 0 ~ 3L)
return(y)
}

m = c(3L, 1L, 0L)
## M12 represents the score of team 1 in a Match vs team 2
match_outcomes = expand.grid(M12 = m, M13 = m, M14 = m, M23 = m, M24 = m, M34 = m)
group_scores_all = match_outcomes %>%
## X1, X2, X3, and X4 are generic placeholders
mutate(
X1 = M12 + M13 + M14,
X2 = rhs(M12) + M23 + M24,
X3 = rhs(M13) + rhs(M23) + M34,
X4 = rhs(M14) + rhs(M24) + rhs(M34)
) %>%
select(X1, X2, X3, X4) %>%
as.matrix()

group_scores_sorted = matrix(nrow = nrow(group_scores_all), ncol = 4)
for(i in 1:nrow(group_scores_all)) {
group_scores_sorted[i, ] = sort(group_scores_all[i, ], decreasing = TRUE)
}
unique_group_scores = unique(as.data.frame(group_scores_sorted)) %>%
arrange(desc(V1), desc(V2), desc(V3), desc(V4))
names(unique_group_scores) = c(LETTERS[1:4])
## And now we have sorted the quadruples and identified the unique quadruples

## Counting Uniques
freq_data = unique_group_scores %>%
mutate(id = paste0(A, B, C, D)) %>%
left_join(
y = as.data.frame(group_scores_sorted) %>% mutate(ones = 1),
by = c("A" = "V1", "B" = "V2", "C" = "V3", "D" = "V4")) %>%
group_by(A, B, C, D, id) %>%
summarize(count = sum(ones)) %>%
ungroup() %>%
mutate(x = row_number())

## Distinguishing Different Counts
diff_freq_data = freq_data %>%
mutate(unequal = (A != B & B != C & C != D)) %>%
arrange(desc(unequal), x)

A B C D
5 4 3 2
6 5 4 1
7 4 3 1
A B C D
7 4 3 2
7 5 2 1
7 5 3 1
7 5 4 0
A B C D
7 6 2 1
7 6 3 1
7 6 4 0
9 4 2 1
A B C D
9 4 3 1
9 6 3 0

## How Common is that set of Group Scores?

There are $$3^6 = 729$$ possible combinations of outcomes which lead to 40 unique quadruples, 13 of which consist of different scores. How many times does each group score occur (under an equal team strengths condition)? Below you will find the frequencies of each quadruple, which are approximately ordered from left to right from “most parity” to “least parity”. The first quadruple $$(3, 3, 3, 3)$$ is the only one that occurs once – it can only occur when every game ends in a tie. Note that every quadruple with different scores can happen $$4! = 24$$ times.