File Coverage

blib/lib/Math/NumSeq/AlphabeticalLengthSteps.pm
Criterion Covered Total %
statement 13 15 86.6
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 18 20 90.0


line stmt bran cond sub pod time code
1             # Copyright 2012, 2015 Kevin Ryde
2              
3             # This file is part of Math-NumSeq-Alpha.
4             #
5             # Math-NumSeq-Alpha 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-Alpha 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-Alpha. If not, see .
17              
18              
19              
20             # Should values in cycles be all 0 ?
21              
22              
23              
24              
25              
26             package Math::NumSeq::AlphabeticalLengthSteps;
27 1     1   752 use 5.004;
  1         3  
  1         32  
28 1     1   3 use strict;
  1         2  
  1         34  
29 1     1   5 use List::Util 'min';
  1         1  
  1         88  
30              
31 1     1   5 use vars '$VERSION', '@ISA';
  1         1  
  1         51  
32             $VERSION = 3;
33 1     1   309 use Math::NumSeq;
  0            
  0            
34             use Math::NumSeq::Base::IterateIth;
35             @ISA = ('Math::NumSeq::Base::IterateIth',
36             'Math::NumSeq');
37             *_is_infinite = \&Math::NumSeq::_is_infinite;
38              
39             use Math::NumSeq::AlphabeticalLength;
40              
41             # uncomment this to run the ### lines
42             #use Smart::Comments;
43              
44              
45             # use constant name => Math::NumSeq::__('...');
46             use constant description => Math::NumSeq::__('Steps of alphabetical length until reaching a cycle.');
47             use constant default_i_start => 1;
48             use constant characteristic_count => 1;
49             use constant characteristic_smaller => 1;
50             use constant characteristic_integer => 1;
51              
52             *parameter_info_array
53             = \&Math::NumSeq::AlphabeticalLength::parameter_info_array;
54              
55             sub values_min {
56             my ($self) = @_;
57             ### oeis_anum: $self
58             if (defined (my $values_min = $self->{'values_min'})) {
59             return $values_min;
60             }
61             my $i_start = $self->i_start;
62             return ($self->{'values_min'}
63             = min (map {$self->ith($_)}
64             $i_start .. $i_start + 20));
65             }
66              
67             #------------------------------------------------------------------------------
68             # A133418 single step towards 4
69              
70             my %oeis_anum = (A005589 => 'A016037', # en cardinals
71             );
72             sub oeis_anum {
73             my ($self) = @_;
74             return $oeis_anum{$self->{'lenseq'}->oeis_anum || ''};
75             }
76              
77             # forty two = 8
78             # eight = 5
79             # five = 4
80             # four = 4
81              
82             # forty three = 10
83             # ten = 3
84             # three = 5
85             # five = 4
86             # four = 4
87             #
88             # forty three = 11 ... is 5 steps
89              
90             # forty four = 9
91             # nine = 4
92             # four = 4
93              
94             # fifty seven = 11
95             # eleven = 6
96             # size = 3
97             # three = 5
98             # five = 4
99             # four = 4 is 5 steps
100             #
101             # fifty seven = 10 ... is 4 steps
102              
103              
104             #------------------------------------------------------------------------------
105              
106             sub new {
107             ### AlphabeticalLengthSteps new(): @_
108             my $self = shift->SUPER::new(@_);
109             $self->{'lenseq'} = Math::NumSeq::AlphabeticalLength->new(@_);
110             return $self;
111             }
112              
113             sub ith {
114             my ($self, $i) = @_;
115             ### AlphabeticalLengthSteps ith(): $i
116              
117             if (_is_infinite($i)) {
118             return undef;
119             }
120              
121             my $count = 0;
122             my %seen;
123             for (;;) {
124             $seen{$i} = undef;
125             $i = $self->{'lenseq'}->ith($i);
126             if (! defined $i) {
127             return undef;
128             }
129             ### to: $i
130             last if exists $seen{$i};
131             $count++;
132             }
133              
134             return $count;
135             }
136              
137             1;
138             __END__