**The Devil is in the Data**, and kindly contributed to R-bloggers)

## Euler Problem 4 Definition

A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99. Find the largest palindrome made from the product of two 3-digit numbers.

## Solution

This code searches fo palindromic numbers, starting at the highest values. The palindromes are tested by converting the number to a character string. When the first palindromic number is found, the loop is broken.

# Cycles through all number combinations, starting at 999 for (i in 999:900) { for (j in 990:900) { word <- as.character(i * j) # Create reverse reverse <- paste(rev(unlist(strsplit(word, ""))), collapse = "") # Check whether palindrome palindrome <- word == reverse if (palindrome) break } if (palindrome) { break } } answer <- i * j

Searching a bit further results in twelve palindromic numbers. Sequence A002113 in the OEIS lists palindromes in base 10. Mathematicians used these numbers only for fun, without any purpose in reality. The graph below shows the number of palindromic numbers between 0 and 1 million.

The post Euler Problem 4: Largest Palindromic Product appeared first on The Devil is in the Data.

**leave a comment**for the author, please follow the link and comment on their blog:

**The Devil is in the Data**.

R-bloggers.com offers

**daily e-mail updates**about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...