All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Numbers
Consecutive Near Palindromes (Posted on 2008-02-13) Difficulty: 3 of 5
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.

See The Solution Submitted by Brian Smith    
Rating: 3.3333 (3 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution brute force perl solution | Comment 8 of 9 |
#!/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
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (1)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (14)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information