Skip to content

Instantly share code, notes, and snippets.

@rexarski
Created March 11, 2022 20:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rexarski/5339d53cc42f8a3a5ea360867af27dfc to your computer and use it in GitHub Desktop.
Save rexarski/5339d53cc42f8a3a5ea360867af27dfc to your computer and use it in GitHub Desktop.
library(tidyverse)
set.seed(1234234)
my_selection <- c(6, 7, 8, 9)
dat0 <- expand_grid(a = 1:6, b = 1:6, c = 1:6, d = 1:6)
dat0 <- dat0 |>
mutate(
sum12 = a + b,
sum13 = a + c,
sum14 = a + d,
sum23 = b + c,
sum24 = b + d,
sum34 = c + d,
win = if_else(sum12 %in% my_selection |
sum13 %in% my_selection |
sum14 %in% my_selection |
sum23 %in% my_selection |
sum24 %in% my_selection |
sum34 %in% my_selection,
TRUE, FALSE
)
)
paste0(
"There are ",
sum(dat0$win),
" winning cases out of all 1296 possible combinations. ",
"The winning rate is: ", mean(dat0$win)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment