line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright 2012, 2013, 2014 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 . |
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
|
|
|
1
|
|
3344
|
use 5.004; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
55
|
|
29
|
1
|
|
|
1
|
|
8
|
use strict; |
|
1
|
|
|
|
|
85
|
|
|
1
|
|
|
|
|
71
|
|
30
|
|
|
|
|
|
|
|
31
|
1
|
|
|
1
|
|
8
|
use vars '$VERSION','@ISA'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
96
|
|
32
|
|
|
|
|
|
|
$VERSION = 71; |
33
|
|
|
|
|
|
|
|
34
|
1
|
|
|
1
|
|
7
|
use Math::NumSeq 7; # v.7 for _is_infinite() |
|
1
|
|
|
|
|
17
|
|
|
1
|
|
|
|
|
78
|
|
35
|
|
|
|
|
|
|
@ISA = ('Math::NumSeq'); |
36
|
|
|
|
|
|
|
*_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
|
|
|
1
|
|
7
|
use constant description => Math::NumSeq::__('Sequence of repeated replacements.'); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
43
|
1
|
|
|
1
|
|
6
|
use constant values_min => 1; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
134
|
|
44
|
|
|
|
|
|
|
sub values_max { |
45
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
46
|
0
|
|
|
|
|
0
|
my $stage = $self->{'stage'}; |
47
|
0
|
0
|
|
|
|
0
|
return ($stage < 0 ? undef : $stage+1); |
48
|
|
|
|
|
|
|
} |
49
|
1
|
|
|
1
|
|
9
|
use constant i_start => 1; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
59
|
|
50
|
1
|
|
|
1
|
|
6
|
use constant characteristic_smaller => 1; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
48
|
|
51
|
1
|
|
|
1
|
|
6
|
use constant characteristic_integer => 1; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
76
|
|
52
|
|
|
|
|
|
|
|
53
|
1
|
|
|
|
|
556
|
use constant parameter_info_array => |
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
|
|
|
1
|
|
6
|
]; |
|
1
|
|
|
|
|
2
|
|
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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
sub oeis_anum { |
79
|
1
|
|
|
1
|
1
|
4
|
my ($self) = @_; |
80
|
1
|
|
|
|
|
5
|
return $oeis_anum[$self->{'stage'}+1]; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub rewind { |
86
|
3
|
|
|
3
|
1
|
769
|
my ($self) = @_; |
87
|
3
|
|
|
|
|
21
|
$self->{'i'} = $self->i_start; |
88
|
3
|
|
|
|
|
23
|
my $count = $self->{'count'} = [undef, [], []]; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
sub next { |
91
|
24
|
|
|
24
|
1
|
819
|
my ($self) = @_; |
92
|
|
|
|
|
|
|
### ReReplace next(): $self->{'i'} |
93
|
|
|
|
|
|
|
|
94
|
24
|
|
|
|
|
38
|
my $stage = $self->{'stage'}; |
95
|
24
|
50
|
|
|
|
49
|
if ($stage == 0) { |
96
|
0
|
|
|
|
|
0
|
return ($self->{'i'}++, |
97
|
|
|
|
|
|
|
1); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
24
|
|
|
|
|
34
|
my $count = $self->{'count'}; |
101
|
|
|
|
|
|
|
### $count |
102
|
|
|
|
|
|
|
|
103
|
24
|
|
|
|
|
29
|
my $value = 1; |
104
|
24
|
|
|
|
|
50
|
for my $level (2 .. $#$count) { |
105
|
|
|
|
|
|
|
### $level |
106
|
|
|
|
|
|
|
### $value |
107
|
|
|
|
|
|
|
### count: ($count->[$level]->[$value]||0) + 1 |
108
|
|
|
|
|
|
|
|
109
|
86
|
100
|
|
|
|
191
|
if (++$count->[$level]->[$value] >= $level) { |
110
|
26
|
|
|
|
|
34
|
$count->[$level]->[$value] = 0; |
111
|
26
|
|
|
|
|
37
|
$value = $level; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
24
|
50
|
33
|
|
|
157
|
if ($value >= $#$count-1 |
|
|
|
66
|
|
|
|
|
116
|
|
|
|
|
|
|
&& ($stage < 0 || $value < $stage)) { |
117
|
8
|
|
|
|
|
11
|
push @$count, [ @{$count->[-1]} ]; # array copy |
|
8
|
|
|
|
|
26
|
|
118
|
|
|
|
|
|
|
### extended to: $count |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
### return: $value |
122
|
24
|
|
|
|
|
78
|
return ($self->{'i'}++, |
123
|
|
|
|
|
|
|
$value); |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub pred { |
127
|
12
|
|
|
12
|
1
|
56
|
my ($self, $value) = @_; |
128
|
|
|
|
|
|
|
### Runs pred(): $value |
129
|
|
|
|
|
|
|
|
130
|
12
|
|
33
|
|
|
52
|
return ($value >= 1 |
131
|
|
|
|
|
|
|
&& $value == int($value)); |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
1; |
135
|
|
|
|
|
|
|
__END__ |