a lazy c++ solution :)
auto larget_palindrome_product(size_t n_digits) -> size_t { const auto is_palidrome = [](size_t x) -> bool { const auto as_string = std::to_string(x); auto fst = as_string.begin(); auto lst = as_string.rbegin(); for (; fst != as_string.end(); fst++, lst++) if (*fst != *lst) return false; return true; }; size_t result = 0; const auto lower_bound = std::pow(10, n_digits - 1); const auto upper_bound = std::pow(10, n_digits) - 1; for (size_t fst = lower_bound; fst <= upper_bound; fst++) { for (size_t snd = fst; snd <= upper_bound; snd++) { if (auto n = fst * snd; is_palidrome(n) && n > result) { result = fst * snd; } } } return result; }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
a lazy c++ solution :)