| 1 | # Copyright 2011, 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 | package Math::NumSeq::PrimeIndexOrder; | ||||||||||||||||||||
| 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 | 1 | ▶ | use Math::NumSeq; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 25 | 1 | @ISA = ('Math::NumSeq'); | |||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 1 | ▶ | use Math::NumSeq::Primes; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | # uncomment this to run the ### lines | ||||||||||||||||||||
| 31 | #use Smart::Comments; | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | 1 | ▶ | use constant name => Math::NumSeq::__('Prime Index Order'); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 34 | 1 | ▶ | use constant description => Math::NumSeq::__('An order of primeness, being how many steps of prime at prime index until reaching a composite.'); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 35 | 1 | ▶ | use constant characteristic_count => 1; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 36 | 1 | ▶ | use constant characteristic_smaller => 1; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 37 | 1 | ▶ | use constant characteristic_increasing => 0; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | 1 | ▶ | use constant parameter_info_array => | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 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 | ]; | |||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 1 | my %values_min = (all => 0, | |||||||||||||||||||
| 54 | primes => 1); | ||||||||||||||||||||
| 55 | 2 | ▶ | sub values_min { | ||||||||||||||||||
|
Subroutine
values_min: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 56 | 2 | my ($self) = @_; | |||||||||||||||||||
| 57 | 2 | return $values_min{$self->{'on_values'}}; | |||||||||||||||||||
| 58 | } | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 1 | my %oeis_anum = (primes => 'A049076', | |||||||||||||||||||
| 61 | # OEIS-Catalogue: A049076 on_values=primes | ||||||||||||||||||||
| 62 | ); | ||||||||||||||||||||
| 63 | 2 | ▶ | sub oeis_anum { | ||||||||||||||||||
|
Subroutine
oeis_anum: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 64 | 2 | my ($self) = @_; | |||||||||||||||||||
| 65 | 2 | return $oeis_anum{$self->{'on_values'}}; | |||||||||||||||||||
| 66 | } | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | 6 | ▶ | sub rewind { | ||||||||||||||||||
|
Subroutine
rewind: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 69 | 6 | my ($self) = @_; | |||||||||||||||||||
| 70 | 6 | $self->{'i'} = $self->i_start; | |||||||||||||||||||
| 71 | 6 | my $seq = Math::NumSeq::Primes->new; | |||||||||||||||||||
| 72 | 6 | $self->{'seqs'} = [ $seq ]; | |||||||||||||||||||
| 73 | 6 | $seq->next; | |||||||||||||||||||
| 74 | 6 | $self->{'targets'} = [ 2 ]; | |||||||||||||||||||
| 75 | } | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | 48 | ▶ | sub next { | ||||||||||||||||||
|
Subroutine
next: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||
| 78 | 48 | my ($self) = @_; | |||||||||||||||||||
| 79 | ### PrimeIndexOrder next(): $self->{'i'} | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | 48 | my $i = $self->{'i'}++; | |||||||||||||||||||
| 82 | 48 | my $targets = $self->{'targets'}; | |||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | 48 | my $level = 0; | |||||||||||||||||||
| 85 | 48 | my $k; | |||||||||||||||||||
| 86 | 48 | ▶ | if ($self->{'on_values'} ne 'primes') { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 87 | 34 | ▶ | if ($i < $targets->[0]) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 88 | 20 | return ($i, 0); | |||||||||||||||||||
| 89 | } | ||||||||||||||||||||
| 90 | } | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | 28 | for (;;) { | |||||||||||||||||||
| 93 | 56 | ($k, $targets->[$level]) = $self->{'seqs'}->[$level]->next; | |||||||||||||||||||
| 94 | 56 | $k--; | |||||||||||||||||||
| 95 | 56 | ▶ | if ($level >= $#$targets) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 96 | 16 | my $seq = Math::NumSeq::Primes->new; | |||||||||||||||||||
| 97 | 16 | push @{$self->{'seqs'}}, $seq; | |||||||||||||||||||
| 98 | 16 | (undef, $targets->[$level+1]) = $seq->next; | |||||||||||||||||||
| 99 | } | ||||||||||||||||||||
| 100 | 56 | $level++; | |||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | ### $k | ||||||||||||||||||||
| 103 | ### $level | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | 56 | ▶ | if ($k < $targets->[$level]) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 106 | 28 | return ($i, $level); | |||||||||||||||||||
| 107 | } | ||||||||||||||||||||
| 108 | } | ||||||||||||||||||||
| 109 | } | ||||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | 24 | ▶ | sub pred { | ||||||||||||||||||
|
Subroutine
pred: called CC=2 SCAR=8.1
Pod
documented
| |||||||||||||||||||||
| 112 | 24 | my ($self, $value) = @_; | |||||||||||||||||||
| 113 | 24 | ▶ | return ($value == int($value) | ||||||||||||||||||
|
Condition33%1/3
$value == int $value && $value >= 0
MC/DC0%0/2
$value == int $value && $value >= 0
$value == int $value
$value >= 0
Truth table33%1/3
A && B
A= $value == int $valueB= $value >= 0
| |||||||||||||||||||||
| 114 | && $value >= 0); | ||||||||||||||||||||
| 115 | } | ||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | 1 | 1; | |||||||||||||||||||
| 118 | __END__ | ||||||||||||||||||||