
ALT library(tidyverse) library(adventdrob) d <- advent_input(1, 2023) # Part 1 d %>% extract(x, c("first"), "(\\d)", remove = FALSE) %>% extract(x, "last", ".*(\\d)", remove = FALSE) %>% mutate(n = as.numeric(paste0(first, last))) %>% summarize(sum(n, na.rm = T)) # Part 2 num <- c("one", "two", "three", "four", "five", "six", "seven", "eight", "nine") d %>% extract(x, "first", "(\\d|one|two|three|four|five|six|seven|eight|nine)", remove = FALSE) %>% extract(x, "last", ".*(\\d|one|two|three|four|five|six|seven|eight|nine)") %>% mutate(first = coalesce(as.numeric(first), match(first, num)), last = coalesce(as.numeric(last), match(last, num))) %>% mutate(n = as.numeric(paste0(first, last))) %>% summarize(sum(n, na.rm = T))




















