| 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
| |||||||||||||||||||||
| 57 | 0 | $digit = $radix-1; | |||||||||||||||||||
| 58 | ▶ | } elsif ($digit >= $radix || $digit == 0) { | |||||||||||||||||||
|
Condition66%2/3
$digit >= $radix or $digit == 0
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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | 712 | my $count = 0; | |||||||||||||||||||
| 76 | 712 | ▶ | while ($i) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 77 | 1768 | ▶ | if (($i % $radix) == $digit) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
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
| |||||||||||||||||||||
| 90 | } | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | 1 | 1; | |||||||||||||||||||
| 93 | __END__ | ||||||||||||||||||||