File Coverage

blib/lib/Math/NumSeq/PrimeIndexOrder.pm
Criterion Covered Total %
statement 63 63 100.0
branch 8 8 100.0
condition 1 3 33.3
subroutine 16 16 100.0
pod 5 5 100.0
total 93 95 97.8


line stmt bran cond sub pod time code
1             # Copyright 2011, 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             package Math::NumSeq::PrimeIndexOrder;
19 1     1   1076 use 5.004;
  1         3  
20 1     1   7 use strict;
  1         2  
  1         38  
21              
22 1     1   4 use vars '$VERSION', '@ISA';
  1         1  
  1         61  
23             $VERSION = 72;
24 1     1   3 use Math::NumSeq;
  1         2  
  1         24  
25             @ISA = ('Math::NumSeq');
26              
27 1     1   3 use Math::NumSeq::Primes;
  1         1  
  1         25  
28              
29              
30             # uncomment this to run the ### lines
31             #use Smart::Comments;
32              
33 1     1   4 use constant name => Math::NumSeq::__('Prime Index Order');
  1         1  
  1         3  
34 1     1   3 use constant description => Math::NumSeq::__('An order of primeness, being how many steps of prime at prime index until reaching a composite.');
  1         2  
  1         3  
35 1     1   4 use constant characteristic_count => 1;
  1         1  
  1         33  
36 1     1   3 use constant characteristic_smaller => 1;
  1         1  
  1         38  
37 1     1   4 use constant characteristic_increasing => 0;
  1         1  
  1         94  
38              
39 1         3 use constant parameter_info_array =>
40             [
41             { name => 'on_values',
42             share_key => 'on_values_primes',
43             display => Math::NumSeq::__('On Values'),
44             type => 'enum',
45             default => 'all',
46             choices => ['all','primes'],
47             choices_display => [Math::NumSeq::__('All'),
48             Math::NumSeq::__('Primes')],
49             description => Math::NumSeq::__('Values to act on, either all integers or just the primes.'),
50             },
51 1     1   4 ];
  1         1  
52              
53             my %values_min = (all => 0,
54             primes => 1);
55             sub values_min {
56 2     2 1 11 my ($self) = @_;
57 2         6 return $values_min{$self->{'on_values'}};
58             }
59              
60             my %oeis_anum = (primes => 'A049076',
61             # OEIS-Catalogue: A049076 on_values=primes
62             );
63             sub oeis_anum {
64 2     2 1 6 my ($self) = @_;
65 2         4 return $oeis_anum{$self->{'on_values'}};
66             }
67              
68             sub rewind {
69 6     6 1 769 my ($self) = @_;
70 6         15 $self->{'i'} = $self->i_start;
71 6         18 my $seq = Math::NumSeq::Primes->new;
72 6         10 $self->{'seqs'} = [ $seq ];
73 6         49 $seq->next;
74 6         21 $self->{'targets'} = [ 2 ];
75             }
76              
77             sub next {
78 48     48 1 789 my ($self) = @_;
79             ### PrimeIndexOrder next(): $self->{'i'}
80              
81 48         46 my $i = $self->{'i'}++;
82 48         29 my $targets = $self->{'targets'};
83              
84 48         29 my $level = 0;
85 48         32 my $k;
86 48 100       69 if ($self->{'on_values'} ne 'primes') {
87 34 100       45 if ($i < $targets->[0]) {
88 20         24 return ($i, 0);
89             }
90             }
91              
92 28         15 for (;;) {
93 56         87 ($k, $targets->[$level]) = $self->{'seqs'}->[$level]->next;
94 56         40 $k--;
95 56 100       72 if ($level >= $#$targets) {
96 16         31 my $seq = Math::NumSeq::Primes->new;
97 16         13 push @{$self->{'seqs'}}, $seq;
  16         19  
98 16         23 (undef, $targets->[$level+1]) = $seq->next;
99             }
100 56         31 $level++;
101              
102             ### $k
103             ### $level
104              
105 56 100       75 if ($k < $targets->[$level]) {
106 28         50 return ($i, $level);
107             }
108             }
109             }
110              
111             sub pred {
112 24     24 1 73 my ($self, $value) = @_;
113 24   33     91 return ($value == int($value)
114             && $value >= 0);
115             }
116              
117             1;
118             __END__