Find a set of four consecutive six digit numbers which satisfies the following:
- The last four digits of the first (smallest) number form a palindrome.
- The last five digits of the second number form a palindrome.
- The second through fifth digits of the third number form a palindrome.
- The fourth (largest) number is a palindrome.
#!/usr/bin/perl
# Use regular expression to check for partial palindromes
my ($p1,$p2,$p3); # number plus 1, plus 2, plus 3
for (100000..999996) { # all 6-digit numbers
($p1,$p2,$p3)=($_+1, $_+2, $_+3);
next unless /^\d\d(\d)(\d)\2\1$/;
next unless $p1=~/^\d(\d)(\d)\d\2\1$/;
next unless $p2=~/^\d(\d)(\d)\2\1\d$/;
next unless $p3=~/^(\d)(\d)(\d)\3\2\1$/;
die "First number: $_\n"
}
__END__
First number: 198888
|
Posted by Moira
on 2009-01-22 00:50:47 |