# Untitled

By: a guest on Mar 12th, 2011  |  syntax: Perl  |  size: 0.57 KB  |  hits: 57  |  expires: Never
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
1. \$L = 1000;
2.
3. for (\$A = 100 ; \$A < \$L ; \$A++)
4. {
5.         for (\$B = 100 ; \$B < \$L ; \$B++)
6.         {
7.                 \$P = \$A*\$B;
8.                 if ( substr(\$P, 0, 1) == substr(\$P, (length(\$P)-1), (length(\$P))) &&
9.                      substr(\$P, 1, 2) == substr(\$P, (length(\$P)-2), (length(\$P)-1)) &&
10.                      substr(\$P, 2, 3) == substr(\$P, (length(\$P)-3), (length(\$P)-2)) &&
11.                      length(\$P) == 6)
12.                 {
13.                         print \$A, " x " , \$B, " = ", \$P, "\n";
14.                         push @array, \$P;
15.                 }
16.         }
17. }
18.
19. \$max = \$array[0];
20.
21. foreach \$i (@array[1..\$#array])
22. {
23.         if (\$i > \$max)
24.         {
25.                 \$max = \$i;
26.         }
27. }
28.
29. print "The largest palindrome is " , \$max , "\n";