| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Math::Abacus; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
55689
|
use v5.10.0; |
|
|
1
|
|
|
|
|
4
|
|
|
4
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
64
|
|
|
5
|
1
|
|
|
1
|
|
6
|
use feature 'say'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
787
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
my $len = 10; |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub num_of_digit { |
|
10
|
0
|
|
0
|
0
|
0
|
|
$len = $_[1] || $len; |
|
11
|
0
|
|
|
|
|
|
return $len; |
|
12
|
|
|
|
|
|
|
} |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
|
15
|
0
|
|
|
0
|
0
|
|
my ($class) = @_; |
|
16
|
0
|
|
|
|
|
|
my ($val) = ($_[1] =~ /(\d*)/); |
|
17
|
0
|
0
|
|
|
|
|
carp "Value extracted: $val.\n" if $_[1] !~ /^\d+$/; |
|
18
|
0
|
0
|
|
|
|
|
carp "The input value is smaller than the maximum length of the abacus.\n" |
|
19
|
|
|
|
|
|
|
if $val >= 10**$len; |
|
20
|
0
|
|
|
|
|
|
bless { |
|
21
|
|
|
|
|
|
|
_value => $val, |
|
22
|
|
|
|
|
|
|
}, $class; |
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub value { |
|
26
|
0
|
|
|
0
|
0
|
|
return $_[0]->{_value}; |
|
27
|
|
|
|
|
|
|
} |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub add { |
|
30
|
0
|
|
|
0
|
1
|
|
my ($self, $v_add) = @_; |
|
31
|
0
|
0
|
|
|
|
|
croak "Only non-negative integer operation.\n" if $v_add !~ /^\d+$/; |
|
32
|
0
|
|
|
|
|
|
$self->{_value} += $v_add; |
|
33
|
0
|
0
|
|
|
|
|
carp "The input value is smaller than the maximum length of the abacus.\n" |
|
34
|
|
|
|
|
|
|
if $self->value >= 10**$len; |
|
35
|
0
|
|
|
|
|
|
return $self; |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub subtract { |
|
39
|
0
|
|
|
0
|
1
|
|
my ($self, $v_sub) = @_; |
|
40
|
0
|
0
|
|
|
|
|
croak "Only non-negative integer operation.\n" if $v_sub !~ /^\d+$/; |
|
41
|
0
|
|
|
|
|
|
$self->{_value} -= $v_sub; |
|
42
|
0
|
0
|
|
|
|
|
carp "The current value of the abacus is negative.\n" |
|
43
|
|
|
|
|
|
|
if $self->value < 0; |
|
44
|
0
|
|
|
|
|
|
return $self; |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub show { |
|
48
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
|
49
|
0
|
|
|
|
|
|
$v = $self->value; |
|
50
|
0
|
0
|
|
|
|
|
_show( |
|
51
|
|
|
|
|
|
|
$v <= 0 ? |
|
52
|
|
|
|
|
|
|
0 : |
|
53
|
|
|
|
|
|
|
$v % (10**$len) |
|
54
|
|
|
|
|
|
|
); |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub _show { |
|
58
|
0
|
|
|
0
|
|
|
my $value = $_[0]; |
|
59
|
0
|
|
|
|
|
|
my @digits = split "", $value; |
|
60
|
0
|
|
|
|
|
|
unshift @digits, (0) x ($len - scalar @digits); |
|
61
|
0
|
|
|
|
|
|
my @mod5dgts = map {$_ % 5} @digits; |
|
|
0
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
my $cross_line = join '-', ('+') x ($len+2); |
|
63
|
0
|
|
|
|
|
|
say $cross_line; |
|
64
|
0
|
|
|
|
|
|
say join " ", '|' , ('x') x $len, '|'; |
|
65
|
0
|
0
|
|
|
|
|
say join " ", '|' , (map {$_ < 5 ? 'x' : '|' } @digits), '|'; |
|
|
0
|
|
|
|
|
|
|
|
66
|
0
|
0
|
|
|
|
|
say join " ", '|' , (map {$_ < 5 ? '|' : 'x' } @digits), '|'; |
|
|
0
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
say $cross_line; |
|
68
|
0
|
|
|
|
|
|
for my $o (0..5) { |
|
69
|
0
|
0
|
|
|
|
|
say join " ", '|' , (map {$_ == $o ? '|' : 'x' } @mod5dgts), '|'; |
|
|
0
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
} |
|
71
|
0
|
|
|
|
|
|
say $cross_line; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 NAME |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Math::Abacus - A toy model of Chinese abacus |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 VERSION |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Version 0.05 |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=cut |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
use Math::Abacus; |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Math::Abacus->num_of_digits(4); |
|
91
|
|
|
|
|
|
|
my $abacus = Math::Abacus->new(460); |
|
92
|
|
|
|
|
|
|
$abacus->add(1); |
|
93
|
|
|
|
|
|
|
$abacus->subtract(5); |
|
94
|
|
|
|
|
|
|
$abacus->show(); |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# PRINT |
|
97
|
|
|
|
|
|
|
+-+-+-+-+-+ |
|
98
|
|
|
|
|
|
|
| x x x x | |
|
99
|
|
|
|
|
|
|
| x x | | | |
|
100
|
|
|
|
|
|
|
| | | x x | |
|
101
|
|
|
|
|
|
|
+-+-+-+-+-+ |
|
102
|
|
|
|
|
|
|
| | x | x | |
|
103
|
|
|
|
|
|
|
| x x x | | |
|
104
|
|
|
|
|
|
|
| x x x x | |
|
105
|
|
|
|
|
|
|
| x x x x | |
|
106
|
|
|
|
|
|
|
| x | x x | |
|
107
|
|
|
|
|
|
|
| x x x x | |
|
108
|
|
|
|
|
|
|
+-+-+-+-+-+ |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 METHODS |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head2 show |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head2 add |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head2 subtract |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 AUTHOR |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Cheok-Yin Fung, C<< >> |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 SUPPORT |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
perldoc Math::Abacus |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
You can also look for information at: |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=over 4 |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
L |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=item * CPAN Ratings |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
L |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=item * Search CPAN |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
L |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=back |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
This software is Copyright (c) 2022 by Cheok-Yin Fung. |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
This is free software, licensed under: |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
MIT License (GPL Compatible) |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=cut |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
1; # End of Math::Abacus |