library(stringr)
get_string <- function(i, input) paste0(str_sub(input, start = i + 1), str_sub(input, end = i))
get_min <- function(input) {
  d <- data.frame(i = 1:str_length(input))
  d$s <- apply(d, 1, get_string, input)
  d <- rbind(c(0, input), d)
  cat(paste(d[order(d$s)[1], ]), '\n')
}

inputs <- c("onion", "bbaaccaadd", "alfalfa", "weugweougewoiheew", "pneumonoultramicroscopicsilicovolcanoconiosis")
invisible(sapply(inputs, get_min))
