Largest palindrome number made from the product of two three-digit numbers
First a function that tests i a number is palindromic. Vectorized!
is_palindromic <- function(x){
y <- as.character(x)
y <- strsplit(y, "")
y <- lapply(y, rev)
y <- lapply(y, paste, collapse = "")
y == x
}
Then all combinations of two three-digit numbers - multiply - get the largest that is palindromic.
t <- expand.grid(100:999, 100:999)
t <- t[,"Var1"] * t[,"Var2"]
answer <- max(t[is_palindromic(t)])