Created
February 9, 2018 16:25
-
-
Save mdlincoln/f6bcc37eeb330e4bfce002d71aa0aedd to your computer and use it in GitHub Desktop.
How many columns does this spreadsheet have?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
letter_position <- function(s) { | |
comp_str <- stringr::str_split(stringr::str_to_lower(s), "") | |
purrr::map_int(comp_str, alpha_index) | |
} | |
alpha_index <- function(s) { | |
i <- purrr::map_int(s, ~ which(. == letters)) | |
purrr::reduce(i, function(x, y) { | |
x * length(letters) + y | |
}) | |
} | |
#> letter_position(c("b", "ah", "qz")) | |
#> [1] 2 34 468 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment