fork download
  1. library(stringr)
  2. get_string <- function(i, input) paste0(str_sub(input, start = i + 1), str_sub(input, end = i))
  3. get_min <- function(input) {
  4. d <- data.frame(i = 1:str_length(input))
  5. d$s <- apply(d, 1, get_string, input)
  6. d <- rbind(c(0, input), d)
  7. cat(paste(d[order(d$s)[1], ]), '\n')
  8. }
  9.  
  10. inputs <- c("onion", "bbaaccaadd", "alfalfa", "weugweougewoiheew", "pneumonoultramicroscopicsilicovolcanoconiosis")
  11. invisible(sapply(inputs, get_min))
  12.  
Success #stdin #stdout 0.2s 182464KB
stdin
Standard input is empty
stdout
2 ionon 
2 aaccaaddbb 
6 aalfalf 
14 eewweugweougewoih 
12 amicroscopicsilicovolcanoconiosispneumonoultr