-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patheuler004.pl
More file actions
executable file
·29 lines (23 loc) · 962 Bytes
/
euler004.pl
File metadata and controls
executable file
·29 lines (23 loc) · 962 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/perl
################################################################################
# Euler 4
# Largest palindrome product
# Author: Eugene Kolo - 2014
# Contact: www.eugenekolo.com
# 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.
#################################################################################
use strict;
my $max = 0;
# Check if the product of every number from 100..999 * 100..999 is a palindrome and compare to the last max
foreach my $firstNum (100..999) {
foreach my $secondNum (100..999) {
my $product = $firstNum * $secondNum;
if ($product eq (reverse $product)) { # A palindrome is defined as $foo == reverse($foo)
if ($max < $product) {
$max = $product;
}
}
}
}
print "$max\n";