06: Tuning Trouble
This looks easy. Oh wait. I totally misread the problem…
do_part <- function(part) {
part <- part - 1
get_vec <- function(vec, place) {
if (place == 0) { return(vec)}
c(vec[-1:(-place)], rep(NA, place))
}
lapply(0:part, function(x) {
get_vec(dt, x)
}) |>
data.frame() |>
`colnames<-`(paste0("X", 1:part)) %>%
apply(1, function(x) {
paste0(x, collapse = "")
}) |>
sapply(function(x) {
max(table(strsplit(x, "")))
}) -> tmp
(which(tmp == 1) + part)[1]
}
Part 1
Hardcoding everything will bite me in the butt later probably. Ultimately not too bad in hindsight.
Part 2
Well, well, well. Hardcoding is never a good move. Took a bit of time to get it figured out, but I got there in the end.
get_vec <- function(vec, place) {
if (place == 0) { return(vec) }
c(vec[-1:(-place)], rep(NA, place))
}
lapply(0:13, function(x) {
get_vec(dt, x)
}) |>
data.frame() |>
`colnames<-`(paste0("X", 1:14)) %>%
apply(1, function(x) {
paste0(x, collapse = "")
}) |>
sapply(function(x) {
max(table(strsplit(x, "")))
}) -> tmp
(which(tmp == 1) + 13)[1]
mdcbnwqgshpvfj
2178