The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Project::Euler::Problem::P004 - Solutions for problem 004 - Largest palindrome from prods

VERSION

version 0.20

HOMEPAGE

http://projecteuler.net/index.php?section=problems&id=4

SYNOPSIS

    use Project::Euler::Problem::P004;
    my $p4 = Project::Euler::Problem::P004->new;

    my $default_answer = $p4->solve;

DESCRIPTION

This module is used to solve problem #004

Given the length of ints to iterate through, we will find the largest product that produces a palindrome.

SETUP

Problem Number

    004

Problem Name

    Largest palindrome from prods

Problem Date

    16 November 2001

Problem Desc

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.

Default Input

The number of digits the numbers should have

Default Answer

    906609

Has Input?

    Yes

Help Message

There is little to no customization for this problem, simply tell it what you want the number of digits to be

INTERNAL FUNCTIONS

Validate Input

The restrictions on custom_input

    A positive integer

Solving the problem

First we will calculate the int that we will be using to loop on. Then we will iterate backwards from that number to the smallest int the same number of digits (ie 999 down to 100). The inner loop will always start with the current outer loop so no duplicate products are tested.

If we ever iterate the outer loop down and that number squared is less than the max number found, then we will stop since it is impossible for any larger number to ever be generated.

AUTHOR

Adam Lesperance <lespea@gmail.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2010 by Adam Lesperance.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.