Project::Euler::Problem::Base - Abstract class that the problems will extend from
version 0.20
package Project::Euler::Problem::P999; use Moose; with 'Project::Euler::Problem::Base';
To ensure that each problem class performs a minimum set of functions, this class will define the basic subroutines and variables that every object must implement.
Problem number on the problem's website
PosInt
_build_problem_number
Short name for the problem designated by the module author
ProblemName
_build_problem_name
Date the problem was posted on the website
MyDateTime
_build_problem_date
Description posted on the problem's website
Str
_build_problem_desc
The base URL for the problems on http://projecteuler.net
http://projecteuler.net/index.php?section=problems&id=
URL to the problem's homepage
ProblemLink
$self->problem_link_base . $self->problem_number
Default input posted on the problem's website
_build_default_input
Answer for the default input
_build_default_answer
Indicates if the problem takes any input from the user
Bool
Whether the problem should use the default input/answer strings
A message to assist the user in using the specific problem
_build_help_message
The user-provided input to the problem
The user-provided answer to the problem
Flag to indicate if the last run was successful
Maybe[Bool
The solved answer from the previous run
Maybe[Str]
The wanted answer from the previous run
Any additional information the last run provided
These two functions must be overridden by the extending class
Ensure the input provided by the user is compliant
This is the main function which will return the status/answer for a problem
This function will point to the internal function that actually solves the problem. Depending on the object attributes that are set, it uses either the default or provided inputs (if they are required). It returns the answer as a string in scalar context, or an array containing the status, calculated answer, and expected answer. If values are passed to the function, then they are taken as the custom_input and custom_answer respectively. This also turns off use_defaults temporarily.
my $problem_1 = Project::Euler::Problem::P001->new(); my $p1_def_answer = $problem_1->solve; $problem_1->custom_input => (42); $problem_1->custom_answer => (24); $problem_1->use_defaults => (0); my $p1_custom_answer = $problem_1->solve; my ($p1_status, $p1_answer, $p1_expected) = $problem_1->solve; # OR # my $problem_2 = Project::Euler::Problem::P002->new(); my $p2_def_answer = $problem_2->solve; # Providing input automatically stops using the defaults my $p2_custom_answer = $problem_2->solve( 1, 4 ); # Provide custom input & answer my ($p2_status, $p2_answer, $p2_expected) = $problem_2->solve;
This function simply returns a nice, readable status message that tells you the outcome of the last run of the module.
my $problem_1 = Project::Euler::Problem::P001->new(); $problem_1->solve; my $message = $problem_1->last_run_message;
Adam Lesperance <lespea@gmail.com>
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.
To install Project::Euler, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Project::Euler
CPAN shell
perl -MCPAN -e shell install Project::Euler
For more information on module installation, please visit the detailed CPAN module installation guide.