Project::Euler::Problem::P001 - Solutions for problem 001 - Sum filtered range
use Project::Euler::Problem::P001; my $p1 = Project::Euler::Problem::P001->new; my $default_answer = $p1->solve; # Use the default filter list of '3, 5' $p1->solve(11); # 3 + 5 + 6 + 9 + 10 == 33 # Didn't override the default answer so status is false! $p1->status; # 0 # Change the filter list $p1->multi_nums(  ); $p1->solve(25, 84); # 4, 8, 12, 16, 20, 24 == 84 # Overrode the default answer with the right one so the status is true $p1->status; # 1
This module is used to solve problem #001
This 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 up to the provided input (1000 by default). The numbers are filtered using Project::Euler::Lib::Utils.
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
Sum filtered list
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.
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!
The restrictions on custom_input
A positve integer
Loop from the first multi_num up to the max_number and filter all numbers that are not multiples of one/all of the multi_nums. Then use the List::More util 'sum' to return the sum of the filtered numbers. If nothing was found return 0 rather than undef.
Adam Lesperance <email@example.com>
This software is copyright (c) 2010 by Adam Lesperance.