#' For a given input list of vectors, calculate sum of all their ranges
#' Used in Day-02 of the Advent of Code 2017
#'
#' @param list_num_vec (list) : list of numeric vectors
#'
#' @export
get_range_numvec <- function(list_num_vec){
list_num_vec %>%
purrr::map(range) %>%
purrr::map(diff) %>%
base::unlist() %>%
sum(na.rm = TRUE) %>%
base::return()
}
#' For a given txt file containing rows of numbers, calculates the sum
#' of their ranges
#' Used in Day-02 of the Advent of Code 2017
#' @param txt_file_path (character) : The path to the valid Day-02 input txt
#' file
#'
#' @export
get_range_txtfile <- function(txt_file_path){
txt_file_path %>%
base::readLines(con = .) %>%
stringr::str_split(string = ., pattern = "\t") %>%
purrr::map(as.numeric) %>%
get_range_numvec(list_num_vec = .) %>%
base::return()
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.