Skip to content

Instantly share code, notes, and snippets.

@JosiahParry
Created February 13, 2021 14:01
Show Gist options
  • Save JosiahParry/39ce0fd844293cb6ce8eb427ab5678f4 to your computer and use it in GitHub Desktop.
Save JosiahParry/39ce0fd844293cb6ce8eb427ab5678f4 to your computer and use it in GitHub Desktop.
library(tidyverse)
unique_sums <- expand.grid(dice_1 = 1:6, dice_2 = 1:6) %>%
mutate(die_sum = dice_1 + dice_2) %>%
pull(die_sum) %>%
unique()
all_divisble <- function(x, divisor) {
divisible_int <- identical((x / divisor), round(x / divisor))
if (divisible_int) {
divisor
} else {
NA_integer_
}
}
expand.grid(x = unique_sums,
divisor = min(unique_sums):max(unique_sums)) %>%
pmap_int(all_divisble) %>%
unique() %>%
na.omit() %>%
length()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment