Skip to content

Instantly share code, notes, and snippets.

@gnp
Created May 14, 2011 05:53
Show Gist options
  • Save gnp/971959 to your computer and use it in GitHub Desktop.
Save gnp/971959 to your computer and use it in GitHub Desktop.
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.
----------
$ perl -e 'I: for ($I = 999; $I >= 100; --$I) { for ($J = $I; $J >= 100; --$J) { $p = $I * $J; $q = scalar reverse $p; if ($p eq $q) { printf "%8d = %3d * %3d\n", $p, $I, $J; } } }' | sort -n -r | head -1
906609 = 993 * 913
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment