Adam Lesperance > Project-Euler > Project::Euler::Problem::P004

Project-Euler-0.20.tar.gz

Dependencies

Annotate this POD

# CPAN RT

 Open 0
View/Report Bugs
Module Version: 0.20

# NAME

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

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;

# 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

`    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.