repeated_twice <- function(id) {
len <- str_length(id)
len %% 2 == 0 &&
str_sub(id, 1, len / 2) == str_sub(id, len / 2 + 1, len)
}
count_repeated_twice <- function(start, end) {
tibble(id = start:end, repeated_twice = map_lgl(id, repeated_twice)) |>
summarise(count = sum(repeated_twice)) |>
pull(count)
}
count_repeated_twice(11, 22)
## [1] 2
count_repeated_twice(95, 115)
## [1] 1
count_repeated_twice(998, 115)
## [1] 0
input |>
mutate(count = map2_int(start, end, count_repeated_twice)) |>
summarise(total = sum(count))
## # A tibble: 1 × 1
## total
## <int>
## 1 822