This is probably the worst thing I have ever written.
@param ... Character vectors representing (large) integers
@return The numbers and the sum are printed to the console
BIGGADDD <- function(...) {
library(magrittr)
dots <- list(...)
res <-
dots %>%
lapply(formatC, width = max(vapply(dots, nchar, 0L)) + 10L) %>%
lapply(strsplit, split = "") %>%
lapply(unlist, recursive = FALSE) %>%
lapply(function(x) {x[!nzchar(x) | x == " "] <- "0"; x}) %>%
lapply(as.integer) %>%
do.call(what = "rbind") %>%
colSums
for (i in rev(seq_along(res))) {
if (res[i] >= 10L) {
res[i - 1L] <- res[i - 1L] + {res[i] %/% 10L}
res[i] <- res[i] %% 10L
}
}
cat(paste0(dots, collapse = "\n"), sep = "")
cat("\n")
cat(sub("^0+", "", paste0(res, collapse = "")), sep = "")
}
x <- paste0(rep("1", 100), collapse = "")
y <- paste0(rep("2", 100), collapse = "")
BIGGADDD(x, y)
#> 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
#> 2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
#> 3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333
Created on 2018-09-27 by the reprex package (v0.2.1)