view release on metacpan or search on metacpan
- refactoring for cleaner solution writing
- add exercise for comparing vulgar fractions
- add missing required modules
- add support for polynoms and power mathematics
- rename option --amount to --quantity
- introduce Math::Complex support
- add experimental chart support with recent LaTeX::Driver and
full working xelatex
0.003 2014-01-15
- redesign of guessing exercise values
- introduce unit exercises
- reduce default amount of exercises
- add exercises for unit, power rules, natural & roman numbers
0.002 2013-11-29
- convert from App::Cmd to MooX::Cmd and MooX::Options
- move to GitHub
- format Changes as per CPAN::Changes::Spec
- modifying default for range being open to [0:
- clean up repository
lib/App/Math/Tutor/Cmd/VulFrac/Cmd/Cast.pm view on Meta::CPAN
sub _get_castable_numbers
{
my ( $self, $quantity ) = @_;
my @result;
while ( $quantity-- )
{
my $vf;
do
{
$vf = $self->_guess_vulgar_fraction;
} while ( !$self->_check_vulgar_fraction($vf) or !$self->_check_decimal_fraction($vf) );
push @result, $vf;
}
@result;
}
sub _build_exercises
{
lib/App/Math/Tutor/Role/Natural.pm view on Meta::CPAN
use Moo::Role;
use App::Math::Tutor::Numbers;
our $VERSION = '0.005';
sub _check_natural_number { $_[0]->value >= 2 }
requires "format";
sub _guess_natural_number
{
my $max_val = $_[0]->format;
my $value = int( rand($max_val) );
NatNum->new( value => $value );
}
=head1 METHODS
=head2 get_natural_number
lib/App/Math/Tutor/Role/Natural.pm view on Meta::CPAN
sub get_natural_number
{
my ( $self, $amount ) = @_;
my @result;
while ( $amount-- )
{
my $nn;
do
{
$nn = $self->_guess_natural_number;
} while ( !_check_natural_number($nn) );
push @result, $nn;
}
@result;
}
=head1 LICENSE AND COPYRIGHT
lib/App/Math/Tutor/Role/Poly.pm view on Meta::CPAN
{
my $values = [ grep { $_->factor } @{ $_[1]->values } ];
scalar @{$values} > 1
and defined $values->[0]->exponent
and $values->[0]->exponent == $_[0]->max_power
and $values->[0]->exponent != 0;
}
requires "max_power", "format", "probability";
sub _guess_polynom
{
my $probability = $_[0]->probability;
my $max_val = $_[0]->format;
my @values;
foreach my $exp ( 0 .. $_[0]->max_power )
{
rand(100) <= $probability or next;
my $value = int( rand( $max_val * 2 ) - $max_val );
push @values,
PolyTerm->new(
lib/App/Math/Tutor/Role/Poly.pm view on Meta::CPAN
sub get_polynom
{
my ( $self, $amount ) = @_;
my @result;
while ( $amount-- )
{
my $nn;
do
{
$nn = $self->_guess_polynom;
} while ( !$self->_check_polynom($nn) );
push @result, $nn;
}
@result;
}
=head1 LICENSE AND COPYRIGHT
lib/App/Math/Tutor/Role/Power.pm view on Meta::CPAN
num => int( rand( $_[1] ) + 1 ),
denum => int( rand( $_[1] ) + 1 )
);
} while ( !$_[0]->_check_vulgar_fraction($vf) );
$vf;
},
},
];
}
sub _guess_power_to
{
my ( $max_basis, $max_exponent ) = @{ $_[0]->format };
my @types = @{ $_[0]->power_types };
my $type = int( rand( scalar @types ) );
my ( $basis, $exponent ) =
( int( rand($max_basis) ), $types[$type]->{builder}->( $_[0], $max_exponent ) );
Power->new(
basis => $basis,
exponent => $exponent,
mode => int( rand(2) )
lib/App/Math/Tutor/Role/Power.pm view on Meta::CPAN
sub get_power_to
{
my ( $self, $amount ) = @_;
my @result;
while ( $amount-- )
{
my $pt;
do
{
$pt = $self->_guess_power_to;
} while ( !_check_power_to($pt) );
push @result, $pt;
}
@result;
}
=head1 LICENSE AND COPYRIGHT
lib/App/Math/Tutor/Role/Roman.pm view on Meta::CPAN
=cut
use Moo::Role;
use App::Math::Tutor::Numbers;
with "App::Math::Tutor::Role::Natural";
our $VERSION = '0.005';
around _guess_natural_number => sub {
my $next = shift;
my $max_val = $_[0]->format;
my $value = int( rand( $max_val - 1 ) ) + 1;
RomanNum->new( value => $value );
};
=head1 LICENSE AND COPYRIGHT
Copyright 2010-2014 Jens Rehsack.
lib/App/Math/Tutor/Role/Unit.pm view on Meta::CPAN
@mult = sort { $b->{factor} <=> $a->{factor} } @mult;
@div = sort { $a->{factor} <=> $b->{factor} } @div;
$ru{base} = scalar @mult;
$ru{spectrum} = [ @mult, @base, @div ];
$ou{$cat} = \%ru;
}
\%ou;
}
sub _guess_unit_number
{
my ( $unit_type, $lb, $ub ) = @_;
my @rc;
$lb == $ub and $lb == scalar @{ $unit_type->{spectrum} } and --$lb;
$lb == $ub and $ub == 0 and scalar @{ $unit_type->{spectrum} } > 0 and ++$ub;
$lb == $ub and $ub < $unit_type->{base} and ++$ub;
$lb == $ub and --$lb;
REDO:
lib/App/Math/Tutor/Role/Unit.pm view on Meta::CPAN
while ( $amount-- )
{
my ( @bounds, $unit );
do
{
@bounds = ( int( rand( scalar @{ $ut->{spectrum} } ) ), int( rand( scalar @{ $ut->{spectrum} } ) ) );
$bounds[0] > $bounds[1] and @bounds = reverse @bounds;
} while ( !$fits->(@bounds) );
$unit = _guess_unit_number( $ut, @bounds );
@result or ( $lo, $uo ) = ( $unit->begin, $unit->end );
push( @result, $unit );
}
@result;
}
=head1 LICENSE AND COPYRIGHT
Copyright 2010-2014 Jens Rehsack.
lib/App/Math/Tutor/Role/VulFrac.pm view on Meta::CPAN
our $VERSION = '0.005';
sub _check_vulgar_fraction
{
$_[1]->num >= 2 and $_[1]->denum >= 2 and $_[1]->num % $_[1]->denum != 0;
}
requires "format";
sub _guess_vulgar_fraction
{
my ( $max_num, $max_denum, $neg ) = ( @{ $_[0]->format }, $_[0]->negativable );
my ( $num, $denum );
( $num, $denum ) =
$neg
? ( int( rand( $max_num * 2 ) - $max_num ), int( rand( $max_denum * 2 ) - $max_denum ) )
: ( int( rand($max_num) ), int( rand($max_denum) ) );
VulFrac->new(
num => $num,
denum => $denum
lib/App/Math/Tutor/Role/VulFrac.pm view on Meta::CPAN
sub get_vulgar_fractions
{
my ( $self, $amount ) = @_;
my @result;
while ( $amount-- )
{
my $vf;
do
{
$vf = $self->_guess_vulgar_fraction;
} while ( !$self->_check_vulgar_fraction($vf) );
push @result, $vf;
}
@result;
}
=head1 LICENSE AND COPYRIGHT