NumSeq/MoranNumbers.pm

filter: Statementstmt 96.7% 59 / 61 Branchbran 85.7% 12 / 14 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 13 / 13 Podpod 100% 3 / 3 totaltotal 93.7% 90 / 96 CC 9 SCAR 12.1
CC
9
Cov
94%
pred
7.2
values_min
3.0
BEGIN
1.0
CRAP 3.4
« NumSeq/MaxDigitCount.pm ↑ Summary NumSeq/WoodallNumbers.pm »
1 # Copyright 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::MoranNumbers;
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 1 ▶use Math::Prime::XS 0.23 'is_prime'; # version 0.23 fix for 1928099
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 1 ▶use vars '$VERSION', '@ISA';
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 $VERSION = 75;
25  
26 1 ▶use Math::NumSeq;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use Math::NumSeq::Base::IteratePred;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 @ISA = ('Math::NumSeq::Base::IteratePred',
29 'Math::NumSeq');
30 1 *_is_infinite = \&Math::NumSeq::_is_infinite;
31  
32 # uncomment this to run the ### lines
33 #use Devel::Comments;
34  
35 1 ▶use constant name => Math::NumSeq::__('Moran Numbers');
Subroutine BEGIN: called CC=1 SCAR=0.0
36 1 ▶use constant description => Math::NumSeq::__('Moran numbers, divisible by the sum of their digits and that division resulting in a prime.');
Subroutine BEGIN: called CC=1 SCAR=0.0
37 1 ▶use constant i_start => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 use Math::NumSeq::Base::Digits
40 1 ▶ 'parameter_info_array'; # radix parameter
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 4 ▶sub values_min {
Subroutine values_min: called CC=3 SCAR=11.0
Pod documented
43 4 my ($self) = @_;
44 4 ▶ if (! $self->{'values_min'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"values_min"}) 1 3 4
45 1 for (my $value = $self->{'radix'}; ; $value++) {
46 9 ▶ if ($self->pred($value)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->pred($value)) 1 8 9
47 1 $self->{'values_min'} = $value;
48 1 last;
49 }
50 }
51 }
52 4 return $self->{'values_min'};
53 }
54  
55 #------------------------------------------------------------------------------
56 # cf A007953 digit sum (in Math::NumSeq::DigitSum)
57 # A085775 both n/digitsum(n) and (n+1)/digitsum(n+1) prime
58 # A108780 n/digitsum(n) is a golden semiprime
59 # A130338 primes not occurring as n/digitsum(n)
60 # A003635 inconsummate, quotients not occurring as n/digitsum(n)
61 #
62 1 my @oeis_anum;
63 1 $oeis_anum[10] = 'A001101'; # OFFSET=1
64 # OEIS-Catalogue: A001101
65  
66 1 ▶sub oeis_anum {
Subroutine oeis_anum: called CC=1 SCAR=0.0
Pod documented
67 1 my ($self) = @_;
68 1 return $oeis_anum[$self->{'radix'}];
69 }
70  
71 #------------------------------------------------------------------------------
72  
73 578 ▶sub pred {
Subroutine pred: called CC=7 SCAR=19.8
Pod documented
74 578 my ($self, $value) = @_;
75 ### MoranNumbers pred(): $value
76  
77 578 ▶ if ($value <= 0 || $value != int($value)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value <= 0 or $value != int $value) 138 440 578
Condition66%2/3
$value <= 0 or $value != int $value
l!l&&r!l&&!r
0138440
MC/DC50%1/2
$value <= 0 or $value != int $value
$value <= 0 $value != int $value
Truth table66%2/3
A or B
A= $value <= 0B= $value != int $value
ABresult
1X1
011
000
78 138 return 0;
79 }
80 440 ▶ if (_is_infinite($value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_infinite($value)) 0 440 440
81 0 return undef;
82 }
83  
84 440 my $radix = $self->{'radix'};
85 440 my $sum = 0;
86 440 my $v = $value;
87 440 ▶ while ($v) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v) 1058 440 1498
88 1058 $sum += ($v % $radix);
89 1058 $v = int($v/$radix);
90 }
91 440 ▶ if ($value % $sum) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value % $sum) 303 137 440
92 303 return 0;
93 }
94 137 $value /= $sum;
95 137 ▶ if ($value > 0xFFFF_FFFF) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value > 4294967295) 0 137 137
96 0 return undef;
97 }
98 137 return is_prime($value);
99 }
100  
101 1 1;
102 __END__
« NumSeq/MaxDigitCount.pm ↑ Summary NumSeq/WoodallNumbers.pm »