helper1_20231201 <- function (df) {
df2 <- df %>%
mutate(digit_locs = X1 %>%
stringr::str_locate_all("[1-9]") %>%
map(~.x[c(1, nrow(.x)), "start"])
) %>%
rowwise() %>%
mutate(X2 = as.numeric(paste0(
stringr::str_sub(X1, start = digit_locs[1], end = digit_locs[1]),
stringr::str_sub(X1, start = digit_locs[2], end = digit_locs[2])
))) %>%
ungroup()
return(df2)
}
df1 <- readr::read_delim("input.txt",
delim = "|",
col_names = FALSE)Day 1 ⋆
Puzzle
Solution
Preprocessing
Part 1
answer1 <- df1 %>%
helper1_20231201() %>%
summarise(sum(X2)) %>%
pull()
print(answer1)[1] 54390
Part 2
I haven’t solved this part yet!