This week’s Riddler Express from FiveThirtyEight: The best team in baseball this year, the Chicago Cubs, have clinched their playoff spot and will play their first playoff game a week from today.
Author
Benjamin Soltoff
Published
October 6, 2016
NoteCode updated
This post was originally written in 2016 and was last rendered under R 4.0.4. The code has been minimally updated to run under R 4.6.1: purrr::rerun(), deprecated in purrr 1.0, was replaced with map() over a sequence. The analysis and its conclusions are unchanged.
The best team in baseball this year, the Chicago Cubs, have clinched their playoff spot and will play their first playoff game a week from today. The Cubs’ road to the World Series title consists of a best-of-five series followed by two best-of-seven series. How many unique strings of wins and losses could the Cubs assemble if they make their way through the playoffs and win their first championship title since 1908? (For example, one possible string would be WWWWWWWWWWW — three straight sweeps. Another would be WWWWWWWLLLWWWW — two sweeps plus a dramatic World Series comeback.)2
A quick and dirty computational approach to calculating all the unique winning combinations.
# get the tidyverse libraries (mainly purrr)library(tidyverse)set.seed(123)# number of simulations to runn_sims <-10000# function to calculate sum of unique series winning combinationscalc_win_combos <-function(games =5, n_sims =10){ series_win <-seq_len(n_sims) %>%map(\(i) sample(c(1, 0), games, replace =TRUE)) %>% unlist %>%matrix(ncol = games, byrow =TRUE) %>% unique %>% rowSums %>% .[] >=ceiling(games /2)return(sum(series_win))}# get total number of unique winning combos for best-of-five# and best-of-seven serieswins_5 <-calc_win_combos(n_sims = n_sims)wins_7 <-calc_win_combos(games =7, n_sims = n_sims)# multiply together (NLDS, NLCS, WS)wins_5 * wins_7 * wins_7