NumSeq/DigitCountLow.pm

filter: Statementstmt 94.5% 70 / 74 Branchbran 77.7% 14 / 18 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 15 / 15 Podpod 100% 3 / 3 totaltotal 89.5% 103 / 115 CC 11 SCAR 13.0
CC
11
Cov
89%
ith
8.1
oeis_anum
3.4
pred
2.3
CRAP 3.7
« NumSeq/PolignacObstinate.pm ↑ Summary NumSeq/Primorials.pm »
1 # Copyright 2010, 2011, 2012, 2013, 2014, 2016, 2019, 2020 Kevin Ryde
2  
3 # This file is part of Math-NumSeq.
4 #
5 # Math-NumSeq is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by the
7 # Free Software Foundation; either version 3, or (at your option) any later
8 # version.
9 #
10 # Math-NumSeq is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 # for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with Math-NumSeq. If not, see <http://www.gnu.org/licenses/>.
17  
18 package Math::NumSeq::DigitCountLow;
19 1 ▶use 5.004;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 1 ▶use vars '$VERSION', '@ISA';
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 $VERSION = 75;
24  
25 1 ▶use Math::NumSeq;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 ▶use Math::NumSeq::Base::IterateIth;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 @ISA = ('Math::NumSeq::Base::IterateIth',
28 'Math::NumSeq');
29 1 *_is_infinite = \&Math::NumSeq::_is_infinite;
30  
31 # uncomment this to run the ### lines
32 #use Smart::Comments;
33  
34  
35 # use constant name => Math::NumSeq::__('Digit Count Low');
36 1 ▶use constant description => Math::NumSeq::__('How many of a given digit at the low end of a number, in a given radix.');
Subroutine BEGIN: called CC=1 SCAR=0.0
37 1 ▶use constant values_min => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 1 ▶use constant default_i_start => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 1 ▶use constant characteristic_count => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 1 ▶use constant characteristic_smaller => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 1 ▶use constant characteristic_increasing => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43 1 ▶use Math::NumSeq::DigitCount 4; # radix,digit parameter
Subroutine BEGIN: called CC=1 SCAR=0.0
44 1 *parameter_info_array = \&Math::NumSeq::DigitCount::parameter_info_array;
45  
46 #------------------------------------------------------------------------------
47 # cf A006519 - highest k s.t. 2^k+1 divides n
48 # A001511 low 0s in 2*n, ie +1
49 # A070940 low 0s pos counting from the left
50 # A051064 low 0s of 3*n in ternary, ie +1
51 # A160094 low zeros in 10 counting from the right from 1
52 # A160093 low zeros in 10 pos counting from the left
53 #
54 1 my @oeis_anum;
55  
56 1 $oeis_anum[1]->[2]->[0] = 'A007814'; # base 2 low 0s, starting i=1
57 # OEIS-Catalogue: A007814 radix=2 digit=0 i_start=1
58  
59 1 $oeis_anum[1]->[3]->[0] = 'A007949'; # base 3 low 0s, starting i=1
60 # OEIS-Catalogue: A007949 radix=3 digit=0 i_start=1
61  
62 1 $oeis_anum[1]->[5]->[0] = 'A112765'; # base 5 low 0s, starting i=1
63 # OEIS-Catalogue: A112765 radix=5 digit=0 i_start=1
64  
65 1 $oeis_anum[1]->[6]->[0] = 'A122841'; # base 6 low 0s, starting i=1
66 # OEIS-Catalogue: A122841 radix=6 digit=0 i_start=1
67  
68 1 $oeis_anum[1]->[10]->[0] = 'A122840'; # base 10 low 0s, starting i=1
69 # OEIS-Catalogue: A122840 radix=10 digit=0 i_start=1
70  
71 4 ▶sub oeis_anum {
Subroutine oeis_anum: called CC=3 SCAR=12.3
Pod documented
72 4 my ($self) = @_;
73 4 my $radix = $self->{'radix'};
74 4 my $digit = $self->{'digit'};
75 4 ▶ if ($digit == -1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($digit == -1) { } 0 4 4
elsif ($digit >= $radix) { } 0 4 4
76 0 $digit = $radix-1;
77 } elsif ($digit >= $radix) {
78 0 return 'A000004'; # all zeros,
79 }
80 4 return $oeis_anum[$self->i_start]->[$radix]->[$digit];
81 }
82  
83 #------------------------------------------------------------------------------
84  
85 499 ▶sub ith {
Subroutine ith: called CC=8 SCAR=20.9
Pod documented
86 499 my ($self, $i) = @_;
87 ### DigitCountLow ith(): $i
88  
89 499 $i = abs($i);
90 499 ▶ if (_is_infinite($i)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_infinite($i)) 0 499 499
91 0 return $i; # don't loop forever if $i is +infinity
92 }
93  
94 499 my $radix = $self->{'radix'};
95 499 my $digit = $self->{'digit'};
96 0 ▶ if ($digit == -1) { $digit = $radix - 1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($digit == -1) 0 499 499
97  
98 499 my $count = 0;
99 499 ▶ if ($radix == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($radix == 2) { } 172 327 499
100 ### binary ...
101 172 ▶ while ($i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i) 289 41 330
102 289 ▶ last unless (($i & 1) == $digit);
Branch: 1 branch
BranchTrueFalseTotal
unless ($i & 1) == $digit 131 158 289
103 158 $count++;
104 158 $i >>= 1;
105 }
106 } else {
107 ### general radix: $radix
108 327 ▶ while ($i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i) 417 14 431
109 417 ▶ last unless (($i % $radix) == $digit);
Branch: 1 branch
BranchTrueFalseTotal
unless $i % $radix == $digit 313 104 417
110 104 $count++;
111 104 $i = int($i/$radix);
112 }
113 }
114 499 return $count;
115 }
116  
117 43 ▶sub pred {
Subroutine pred: called CC=2 SCAR=8.1
Pod documented
118 43 my ($self, $value) = @_;
119 43 ▶ return ($value >= 0 && $value == int($value));
Condition33%1/3
$value >= 0 && $value == int $value
!ll&&!rl&&r
0043
MC/DC0%0/2
$value >= 0 && $value == int $value
$value >= 0 $value == int $value
Truth table33%1/3
A && B
A= $value >= 0B= $value == int $value
ABresult
0X0
100
111
120 }
121  
122 1 1;
123 __END__
« NumSeq/PolignacObstinate.pm ↑ Summary NumSeq/Primorials.pm »