| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::Math::Tutor::Cmd::Natural::Cmd::Add; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
4366
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
30
|
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
34
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
5
|
use vars qw(@ISA $VERSION); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
64
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
App::Math::Tutor::Cmd::Natural::Cmd::Add - Plugin for addition and subtraction of natural numbers |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=cut |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = '0.004'; |
|
15
|
|
|
|
|
|
|
|
|
16
|
1
|
|
|
1
|
|
5
|
use Moo; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
7
|
|
|
17
|
1
|
|
|
1
|
|
318
|
use MooX::Cmd; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
8
|
|
|
18
|
1
|
|
|
1
|
|
1951
|
use MooX::Options; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
9
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has template_filename => ( |
|
21
|
|
|
|
|
|
|
is => "ro", |
|
22
|
|
|
|
|
|
|
default => "twocols" |
|
23
|
|
|
|
|
|
|
); |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
with "App::Math::Tutor::Role::NaturalExercise"; |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub _build_command_names |
|
28
|
|
|
|
|
|
|
{ |
|
29
|
0
|
|
|
0
|
|
0
|
return qw(add sub); |
|
30
|
|
|
|
|
|
|
} |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub _build_exercises |
|
33
|
|
|
|
|
|
|
{ |
|
34
|
1
|
|
|
1
|
|
29
|
my ($self) = @_; |
|
35
|
|
|
|
|
|
|
|
|
36
|
1
|
|
|
|
|
3
|
my (@tasks); |
|
37
|
1
|
|
|
|
|
5
|
foreach my $i ( 1 .. $self->quantity ) |
|
38
|
|
|
|
|
|
|
{ |
|
39
|
15
|
|
|
|
|
15
|
my @line; |
|
40
|
15
|
|
|
|
|
23
|
foreach my $j ( 0 .. 1 ) |
|
41
|
|
|
|
|
|
|
{ |
|
42
|
30
|
|
|
|
|
73
|
my ( $a, $b ) = $self->get_natural_number(2); |
|
43
|
30
|
|
|
|
|
76
|
push @line, [ $a, $b ]; |
|
44
|
|
|
|
|
|
|
} |
|
45
|
15
|
|
|
|
|
33
|
push @tasks, \@line; |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
1
|
|
|
|
|
16
|
my $exercises = { |
|
49
|
|
|
|
|
|
|
section => "Natural number addition / subtraction", |
|
50
|
|
|
|
|
|
|
caption => 'NaturalNums', |
|
51
|
|
|
|
|
|
|
label => 'natural_number_addition', |
|
52
|
|
|
|
|
|
|
header => [ [ 'Natural Number Addition', 'Natural Number Subtraction' ] ], |
|
53
|
|
|
|
|
|
|
solutions => [], |
|
54
|
|
|
|
|
|
|
challenges => [], |
|
55
|
|
|
|
|
|
|
}; |
|
56
|
|
|
|
|
|
|
|
|
57
|
1
|
|
|
|
|
4
|
foreach my $line (@tasks) |
|
58
|
|
|
|
|
|
|
{ |
|
59
|
15
|
|
|
|
|
12
|
my ( @solution, @challenge ); |
|
60
|
|
|
|
|
|
|
|
|
61
|
15
|
|
|
|
|
19
|
foreach my $i ( 0 .. 1 ) |
|
62
|
|
|
|
|
|
|
{ |
|
63
|
30
|
|
|
|
|
28
|
my ( $a, $b ) = @{ $line->[$i] }; |
|
|
30
|
|
|
|
|
44
|
|
|
64
|
30
|
100
|
|
|
|
49
|
my $op = $i ? '-' : '+'; |
|
65
|
30
|
100
|
100
|
|
|
97
|
$op eq '-' and $a < $b and ( $b, $a ) = ( $a, $b ); |
|
66
|
30
|
|
|
|
|
80
|
push @challenge, sprintf( '$ %s %s %s = $', $a, $op, $b ); |
|
67
|
|
|
|
|
|
|
|
|
68
|
30
|
|
|
|
|
61
|
my @way; # remember Frank Sinatra :) |
|
69
|
30
|
|
|
|
|
66
|
push @way, sprintf( '%s %s %s', $a, $op, $b ); |
|
70
|
30
|
100
|
|
|
|
99
|
push @way, $op eq "+" ? $a->_numify + $b->_numify : $a->_numify - $b->_numify; |
|
71
|
|
|
|
|
|
|
|
|
72
|
30
|
|
|
|
|
105
|
push( @solution, '$ ' . join( " = ", @way ) . ' $' ); |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
15
|
|
|
|
|
17
|
push( @{ $exercises->{solutions} }, \@solution ); |
|
|
15
|
|
|
|
|
27
|
|
|
76
|
15
|
|
|
|
|
15
|
push( @{ $exercises->{challenges} }, \@challenge ); |
|
|
15
|
|
|
|
|
32
|
|
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
1
|
|
|
|
|
30
|
return $exercises; |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Copyright 2010-2014 Jens Rehsack. |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
87
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
|
88
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=cut |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |