NumSeq/DigitCountHigh.pm

filter: Statementstmt 95.4% 63 / 66 Branchbran 75.0% 9 / 12 Conditioncond 50.0% 3 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 15 / 15 Podpod 100% 3 / 3 totaltotal 88.6% 94 / 106 CC 9 SCAR 9.4
CC
9
Cov
89%
ith
5.1
oeis_anum
4.2
pred
2.3
CRAP 2.6
« NumSeq/HappyNumbers.pm ↑ Summary NumSeq/RadixConversion.pm »
1 # Copyright 2010, 2011, 2012, 2013, 2014, 2016, 2017, 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::DigitCountHigh;
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  
32 # use constant name => Math::NumSeq::__('Digit Count High');
33 1 ▶use constant description => Math::NumSeq::__('Count of how many of a given digit at the high end of a number, in a given radix.');
Subroutine BEGIN: called CC=1 SCAR=0.0
34 1 ▶use constant values_min => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 1 ▶use constant i_start => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 1 ▶use constant characteristic_count => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 1 ▶use constant characteristic_smaller => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 1 ▶use constant characteristic_increasing => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
39  
40 1 ▶use Math::NumSeq::DigitCount 4;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 1 *parameter_info_array = \&Math::NumSeq::DigitCount::parameter_info_array;
42  
43 1 my @oeis_anum;
44  
45 1 $oeis_anum[2]->[1] = 'A090996'; # leading 1 bits
46 # OEIS-Catalogue: A090996 radix=2
47  
48 # OEIS-Other: A000004 radix=2 digit=0
49 # OEIS-Other: A000004 radix=3 digit=0
50 # OEIS-Other: A000004 radix=10 digit=0
51  
52 3 ▶sub oeis_anum {
Subroutine oeis_anum: called CC=4 SCAR=14.2
Pod documented
53 3 my ($self) = @_;
54 3 my $radix = $self->{'radix'};
55 3 my $digit = $self->{'digit'};
56 3 ▶ if ($digit == -1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($digit == -1) { } 0 3 3
elsif ($digit >= $radix or $digit == 0) { } 1 2 3
57 0 $digit = $radix-1;
58 ▶ } elsif ($digit >= $radix || $digit == 0) {
Condition66%2/3
$digit >= $radix or $digit == 0
l!l&&r!l&&!r
012
MC/DC50%1/2
$digit >= $radix or $digit == 0
$digit >= $radix $digit == 0
Truth table66%2/3
A or B
A= $digit >= $radixB= $digit == 0
ABresult
1X1
011
000
59 1 return 'A000004'; # all zeros,
60 }
61 2 return $oeis_anum[$radix]->[$digit];
62 }
63  
64 712 ▶sub ith {
Subroutine ith: called CC=5 SCAR=16.4
Pod documented
65 712 my ($self, $i) = @_;
66 712 $i = abs($i);
67 712 ▶ if (_is_infinite($i)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_infinite($i)) 0 712 712
68 0 return $i; # don't loop forever if $i is +infinity
69 }
70  
71 712 my $radix = $self->{'radix'};
72 712 my $digit = $self->{'digit'};
73 0 ▶ if ($digit == -1) { $digit = $radix - 1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($digit == -1) 0 712 712
74  
75 712 my $count = 0;
76 712 ▶ while ($i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i) 1768 712 2480
77 1768 ▶ if (($i % $radix) == $digit) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i % $radix == $digit) { } 718 1050 1768
78 718 $count++;
79 } else {
80 1050 $count = 0;
81 }
82 1768 $i = int($i/$radix);
83 }
84 712 return $count;
85 }
86  
87 47 ▶sub pred {
Subroutine pred: called CC=2 SCAR=8.1
Pod documented
88 47 my ($self, $value) = @_;
89 47 ▶ return ($value >= 0 && $value == int($value));
Condition33%1/3
$value >= 0 && $value == int $value
!ll&&!rl&&r
0047
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
90 }
91  
92 1 1;
93 __END__
« NumSeq/HappyNumbers.pm ↑ Summary NumSeq/RadixConversion.pm »