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