good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Re^3: Puzzle: What is the largest integer ... (not "a longest")by fizbin (Chaplain) |
on Oct 27, 2005 at 14:59 UTC ( [id://503363]=note: print w/replies, xml ) | Need Help?? |
Note that you can cut the time in half or there abouts by adding just two simple checks; this version of your program runs in 6.1 seconds on my machine - the original without the initial 9-digit loop takes 13 seconds on my machine:
Note that all I've done is add two regex tests - that you don't have any even digits if the last digit is odd, and that you never have a 5 in any but the last position. Reducing the search space is almost always a good idea.
--
In Section
Seekers of Perl Wisdom
|
|