suppressPackageStartupMessages(library(tidyverse))
spellingbee_20190719 <- readr::read_csv(here::here("spellingbee", "data",
"spellingbee_20190719.csv"),
col_types = cols(date = col_date(format = "%Y-%m-%d"))
)
charlist <- list("m", "e", "t", "p", "c", "o", "l")
#' @description Checks if string contains all the letters specified
#' @string Target string being inspected for all letters
#' @characters list of characters to check for in string
#' @example str_detect_all("complete", characters = charlist)
str_detect_all <- function(string, characters) {
if_else(str_detect(string, purrr::pluck(characters, 1)) &
str_detect(string, purrr::pluck(characters, 2)) &
str_detect(string, purrr::pluck(characters, 3)) &
str_detect(string, purrr::pluck(characters, 4)) &
str_detect(string, purrr::pluck(characters, 5)) &
str_detect(string, purrr::pluck(characters, 6)) &
str_detect(string, purrr::pluck(characters, 7)),
7, 0)
}
spellingbee_scored <- spellingbee_20190719 %>%
mutate(
"length_points" =
case_when(
length == 4 ~ 1,
length == 5 ~ 5,
length == 6 ~ 6,
length == 7 ~ 7,
length == 8 ~ 8,
length == 9 ~ 9,
length == 10 ~ 10,
TRUE ~ 0
),
"pangram_points" = str_detect_all(word, charlist),
"word_points" = length_points + pangram_points
)
mara_spellingbee_score <- spellingbee_scored %>%
mutate("player" = "mara") %>%
arrange(desc(word_points))
DT::datatable(mara_spellingbee_score)
total = sum(mara_spellingbee_score$word_points)
total
## [1] 182