The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Project::Euler::Problem::P001 - Solutions for problem 001

VERSION

Version v0.1.2

SYNOPSIS

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

    use Project::Euler::Problem::P001;
    my $p1 = Project::Euler::Problem::P001->new;

    my $default_answer = $p1->solve;

DESCRIPTION

This module is used to solve problem #001

This simple problem simply needs to find the sum of all the numbers within a range which are multiples of a set of integers. The range always starts at 1 and continues upto the provided input (1000 by default). The numbers are filtered using Project::Euler::Lib::MultipleCheck.

Problem Attributes

Multiple Numbers

An array of positive integers that are used to filter out the number to sum

This array is always kept sorted in order to optimize the solve function

    [3, 5]

SETUP

Problem Number

    001

Problem Name

    Sum filtered list

Problem Date

    2001-10-05

Problem Desc

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.

Find the sum of all the multiples of 3 or 5 below 1000.

Default Input

The maximum value

    1,000

Default Answer

    233,168

Has Input?

    Yes

Help Message

You can change multi_nums to alter the way the program will function. If you are providing custom_input, don't forget to specify the wanted_answer if you know it!

INTERNAL FUNCTIONS

Validate Input

The restrictions on custom_input

    A positve integer

Solving the problem

Tell the multiple_check object what the current multi_nums is. Then loop from the first multi_num to the max_number (- 1) and filter all numbers that retrun false. Finally use the List::More util 'sum' to return the sum of the filtered numbers. If nothing was found return 0 rather than undef.

AUTHOR

Adam Lesperance, <lespea at cpan.org>

BUGS

Please report any bugs or feature requests to bug-project-euler at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Project-Euler. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Project::Euler::Problem::P001

ACKNOWLEDGEMENTS

List::Util

COPYRIGHT & LICENSE

Copyright 2009 Adam Lesperance.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.