Project Euler Problem 4

2014年04月09日

Q

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.

R

First Version

for(i in 100:999)
{
  for(j in 100:999)
  {
    temp <- i*j
    if(temp > 100000)
    {
      if((temp %/% 100000)==(temp %% 10) & (temp %/% 10000) %% 10 == ((temp %/% 10) %% 10) & (temp %/% 1000) %% 10 ==(temp %/% 100) %% 10)
        result <-temp
    }
    else
    {
      if((temp %/% 10000)==(temp %% 10) & (temp %/% 1000) %% 10 == ((temp %/% 10) %% 10))
        result <-temp
    }
  }
}
print(result)