| 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 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | # Benoit Cloitre followups | ||||||||||||||||||||||||||||||||||||||||||
| 21 | # http://sci.tech-archive.net/Archive/sci.math.research/2004-10/0224.html | ||||||||||||||||||||||||||||||||||||||||||
| 22 | # http://sci.tech-archive.net/Archive/sci.math.research/2004-11/0015.html | ||||||||||||||||||||||||||||||||||||||||||
| 23 | # http://sci.tech-archive.net/Archive/sci.math.research/2004-11/0021.html | ||||||||||||||||||||||||||||||||||||||||||
| 24 | # | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | package Math::NumSeq::ReReplace; | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | ▶ | use 5.004; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 1 | ▶ | use vars '$VERSION','@ISA'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | $VERSION = 75; | |||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | ▶ | use Math::NumSeq 7; # v.7 for _is_infinite() | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | @ISA = ('Math::NumSeq'); | |||||||||||||||||||||||||||||||||||||||||
| 36 | 1 | *_is_infinite = \&Math::NumSeq::_is_infinite; | |||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | # uncomment this to run the ### lines | ||||||||||||||||||||||||||||||||||||||||||
| 39 | #use Smart::Comments; | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | # use constant name => Math::NumSeq::__('Repeated Replacement'); | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 1 | ▶ | use constant description => Math::NumSeq::__('Sequence of repeated replacements.'); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 1 | ▶ | use constant values_min => 1; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | sub values_max { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
values_max: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | my $stage = $self->{'stage'}; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | return ($stage < 0 ? undef : $stage+1); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 1 | ▶ | use constant i_start => 1; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 1 | ▶ | use constant characteristic_smaller => 1; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | ▶ | use constant characteristic_integer => 1; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 1 | ▶ | use constant parameter_info_array => | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | [ | ||||||||||||||||||||||||||||||||||||||||||
| 55 | { name => 'stage', | ||||||||||||||||||||||||||||||||||||||||||
| 56 | share_key => 'stage_neg1', | ||||||||||||||||||||||||||||||||||||||||||
| 57 | type => 'integer', | ||||||||||||||||||||||||||||||||||||||||||
| 58 | default => '-1', | ||||||||||||||||||||||||||||||||||||||||||
| 59 | width => 4, | ||||||||||||||||||||||||||||||||||||||||||
| 60 | minimum => -1, | ||||||||||||||||||||||||||||||||||||||||||
| 61 | # description => Math::NumSeq::__('...'), | ||||||||||||||||||||||||||||||||||||||||||
| 62 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 1 | ]; | |||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 66 | # 'A100002' | ||||||||||||||||||||||||||||||||||||||||||
| 67 | # 0 1 2 3 4 5 6 7 8 9 | ||||||||||||||||||||||||||||||||||||||||||
| 68 | # 1, 2, 1, 2, 3, 3, 1, 2, 4, 4, 3, 4, 1, 2, 5, 5, 3, 5, 1, 2, 4, 5, 3, 4, | ||||||||||||||||||||||||||||||||||||||||||
| 69 | # 1 2 1 2 | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | # cf A100287 - first occurrence of n | ||||||||||||||||||||||||||||||||||||||||||
| 72 | # A101224 | ||||||||||||||||||||||||||||||||||||||||||
| 73 | # | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 1 | my @oeis_anum = ('A100002', # -1 all stages | |||||||||||||||||||||||||||||||||||||||||
| 75 | # 0 all-ones, but A000012 has OFFSET=0 | ||||||||||||||||||||||||||||||||||||||||||
| 76 | # 1 is 1,2 rep, but A040001 has OFFSET=0 | ||||||||||||||||||||||||||||||||||||||||||
| 77 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 1 | ▶ | sub oeis_anum { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
oeis_anum: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 80 | 1 | return $oeis_anum[$self->{'stage'}+1]; | |||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | 3 | ▶ | sub rewind { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rewind: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 87 | 3 | $self->{'i'} = $self->i_start; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 3 | my $count = $self->{'count'} = [undef, [], []]; | |||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 24 | ▶ | sub next { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
next: called CC=7 SCAR=19.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 24 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 92 | ### ReReplace next(): $self->{'i'} | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 24 | my $stage = $self->{'stage'}; | |||||||||||||||||||||||||||||||||||||||||
| 95 | 24 | ▶ | if ($stage == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | return ($self->{'i'}++, | |||||||||||||||||||||||||||||||||||||||||
| 97 | 1); | ||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 24 | my $count = $self->{'count'}; | |||||||||||||||||||||||||||||||||||||||||
| 101 | ### $count | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 24 | my $value = 1; | |||||||||||||||||||||||||||||||||||||||||
| 104 | 24 | for my $level (2 .. $#$count) { | |||||||||||||||||||||||||||||||||||||||||
| 105 | ### $level | ||||||||||||||||||||||||||||||||||||||||||
| 106 | ### $value | ||||||||||||||||||||||||||||||||||||||||||
| 107 | ### count: ($count->[$level]->[$value]||0) + 1 | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | 86 | ▶ | if (++$count->[$level]->[$value] >= $level) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 26 | $count->[$level]->[$value] = 0; | |||||||||||||||||||||||||||||||||||||||||
| 111 | 26 | $value = $level; | |||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 24 | ▶ | if ($value >= $#$count-1 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$value >= $count->$#* - 1 and $stage < 0 || $value < $stage
$stage < 0 or $value < $stage
MC/DC33%1/3
$value >= $count->$#* - 1 and $stage < 0 || $value < $stage
$value >= $count->$#* - 1
$stage < 0
$value < $stage
Truth table50%2/4
A and B or C
A= $value >= $count->$#* - 1B= $stage < 0C= $value < $stage
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | && ($stage < 0 || $value < $stage)) { | ||||||||||||||||||||||||||||||||||||||||||
| 117 | 8 | push @$count, [ @{$count->[-1]} ]; # array copy | |||||||||||||||||||||||||||||||||||||||||
| 118 | ### extended to: $count | ||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | ### return: $value | ||||||||||||||||||||||||||||||||||||||||||
| 122 | 24 | return ($self->{'i'}++, | |||||||||||||||||||||||||||||||||||||||||
| 123 | $value); | ||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | 12 | ▶ | sub pred { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pred: called CC=2 SCAR=8.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | 12 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 128 | ### Runs pred(): $value | ||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | 12 | ▶ | return ($value >= 1 | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$value >= 1 && $value == int $value
MC/DC0%0/2
$value >= 1 && $value == int $value
$value >= 1
$value == int $value
Truth table33%1/3
A && B
A= $value >= 1B= $value == int $value
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | && $value == int($value)); | ||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 135 | __END__ | ||||||||||||||||||||||||||||||||||||||||||