NAME
Project::Euler::Problem::Base - Abstract class that the problems will extend from
VERSION
version 0.20
SYNOPSIS
package Project::Euler::Problem::P999;
use Moose;
with 'Project::Euler::Problem::Base';
DESCRIPTION
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.
ATTRIBUTES
problem_number
Problem number on the problem's website
- Isa
-
PosInt
- Requires
-
_build_problem_number
problem_name
Short name for the problem designated by the module author
- Isa
-
ProblemName
- Requires
-
_build_problem_name
problem_date
Date the problem was posted on the website
- Isa
-
MyDateTime
- Requires
-
_build_problem_date
problem_desc
Description posted on the problem's website
- Isa
-
Str
- Requires
-
_build_problem_desc
problem_link_base
The base URL for the problems on http://projecteuler.net
- Isa
-
Str
- Default
-
http://projecteuler.net/index.php?section=problems&id=
problem_link
URL to the problem's homepage
- Isa
-
ProblemLink
- Is
-
$self->problem_link_base . $self->problem_number
default_input
Default input posted on the problem's website
- Isa
-
Str
- Requires
-
_build_default_input
default_answer
Answer for the default input
- Isa
-
Str
- Requires
-
_build_default_answer
has_input
Indicates if the problem takes any input from the user
- Isa
-
Bool
use_defaults
Whether the problem should use the default input/answer strings
- Isa
-
Bool
help_message
A message to assist the user in using the specific problem
- Isa
-
Str
- Requires
-
_build_help_message
custom_input
The user-provided input to the problem
- Isa
-
Str
custom_answer
The user-provided answer to the problem
- Isa
-
Str
solved_status
Flag to indicate if the last run was successful
- Isa
-
Maybe[Bool
solved_answer
The solved answer from the previous run
- Isa
-
Maybe[Str]
solved_wanted
The wanted answer from the previous run
- Isa
-
Maybe[Str]
more_info
Any additional information the last run provided
- Isa
-
Maybe[Str]
ABSTRACT FUNCTIONS
These two functions must be overridden by the extending class
_check_input
Ensure the input provided by the user is compliant
_solve_problem
This is the main function which will return the status/answer for a problem
PROVIDED FUNCTIONS
solve
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.
Example
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;
status
This function simply returns a nice, readable status message that tells you the outcome of the last run of the module.
Example
my $problem_1 = Project::Euler::Problem::P001->new();
$problem_1->solve;
my $message = $problem_1->last_run_message;
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.