| 1 | # Copyright 2010, 2011, 2012, 2013, 2014, 2016, 2017, 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::Beastly; | ||||||||||
| 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 | 1 | ▶ | use List::Util 'max'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | |||||||||||
| 23 | 1 | ▶ | use vars '$VERSION', '@ISA'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 24 | 1 | $VERSION = 75; | |||||||||
| 25 | 1 | ▶ | use Math::NumSeq; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 26 | 1 | @ISA = ('Math::NumSeq'); | |||||||||
| 27 | 1 | *_is_infinite = \&Math::NumSeq::_is_infinite; | |||||||||
| 28 | |||||||||||
| 29 | |||||||||||
| 30 | # use constant name => Math::NumSeq::__('Beastly Numbers'); | ||||||||||
| 31 | 1 | ▶ | use constant description => Math::NumSeq::__('Numbers which contain "666". The default is decimal, or select a radix.'); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 32 | 1 | ▶ | use constant i_start => 1; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 33 | 1 | ▶ | use constant characteristic_increasing => 1; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 34 | 1 | ▶ | use constant characteristic_integer => 1; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 35 | |||||||||||
| 36 | 1 | ▶ | use constant parameter_info_array => | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 37 | [ | ||||||||||
| 38 | { name => 'radix', | ||||||||||
| 39 | share_key => 'radix_min_7', | ||||||||||
| 40 | type => 'integer', | ||||||||||
| 41 | display => Math::NumSeq::__('Radix'), | ||||||||||
| 42 | default => 10, | ||||||||||
| 43 | minimum => 7, # less than 7 there's no beastly values | ||||||||||
| 44 | width => 3, | ||||||||||
| 45 | description => Math::NumSeq::__('Radix, ie. base, for the values calculation. Default is decimal (base 10).'), | ||||||||||
| 46 | }, | ||||||||||
| 47 | 1 | ]; | |||||||||
| 48 | |||||||||||
| 49 | #------------------------------------------------------------------------------ | ||||||||||
| 50 | |||||||||||
| 51 | # cf A131645 the beastly primes | ||||||||||
| 52 | 2 | ▶ | sub oeis_anum { | ||||||||
|
Subroutine
oeis_anum: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 53 | 2 | my ($self) = @_; | |||||||||
| 54 | 2 | ▶ | return ($self->{'radix'} == 10 | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | ? 'A051003' | ||||||||||
| 56 | : undef); | ||||||||||
| 57 | } | ||||||||||
| 58 | # OEIS-Catalogue: A051003 radix=10 | ||||||||||
| 59 | |||||||||||
| 60 | #------------------------------------------------------------------------------ | ||||||||||
| 61 | |||||||||||
| 62 | 2 | ▶ | sub values_min { | ||||||||
|
Subroutine
values_min: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 63 | 2 | my ($self) = @_; | |||||||||
| 64 | 2 | my $radix = $self->{'radix'}; | |||||||||
| 65 | 2 | return (6*$radix+6)*$radix+6; # at i=0 | |||||||||
| 66 | } | ||||||||||
| 67 | |||||||||||
| 68 | 6 | ▶ | sub rewind { | ||||||||
|
Subroutine
rewind: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 69 | 6 | my ($self) = @_; | |||||||||
| 70 | |||||||||||
| 71 | 6 | my $radix = $self->{'radix'}; | |||||||||
| 72 | |||||||||||
| 73 | 6 | $self->{'i'} = $self->i_start; | |||||||||
| 74 | 6 | $self->{'target'} = (6*$radix+6)*$radix+6; | |||||||||
| 75 | 6 | $self->{'cube'} = $radix*$radix*$radix; | |||||||||
| 76 | 6 | $self->{'value'} = $self->{'target'} - 1; | |||||||||
| 77 | } | ||||||||||
| 78 | 204 | ▶ | sub next { | ||||||||
|
Subroutine
next: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||
| 79 | 204 | my ($self) = @_; | |||||||||
| 80 | 204 | ▶ | if ($self->{'radix'} < 7) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 81 | 0 | return; | |||||||||
| 82 | } | ||||||||||
| 83 | 204 | my $value = $self->{'value'}; | |||||||||
| 84 | 204 | for (;;) { | |||||||||
| 85 | 81556 | ▶ | if ($self->pred(++$value)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 86 | 204 | return ($self->{'i'}++, ($self->{'value'} = $value)); | |||||||||
| 87 | } | ||||||||||
| 88 | } | ||||||||||
| 89 | } | ||||||||||
| 90 | |||||||||||
| 91 | 82684 | ▶ | sub pred { | ||||||||
|
Subroutine
pred: called CC=7 SCAR=19.6
Pod
documented
| |||||||||||
| 92 | 82684 | my ($self, $value) = @_; | |||||||||
| 93 | |||||||||||
| 94 | { | ||||||||||
| 95 | 82684 | my $int = int($value); | |||||||||
| 96 | 82684 | ▶ | if ($value != $int) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 97 | 512 | return 0; | |||||||||
| 98 | } | ||||||||||
| 99 | 82172 | $value = $int; # prefer BigInt if input BigFloat | |||||||||
| 100 | } | ||||||||||
| 101 | |||||||||||
| 102 | 82172 | my $radix = $self->{'radix'}; | |||||||||
| 103 | 82172 | ▶ | if ($radix < 7) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 104 | 0 | return 0; # no digit 6s at all if radix<7 | |||||||||
| 105 | } | ||||||||||
| 106 | 82172 | ▶ | if ($radix == 10) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 107 | 58060 | return ($value =~ /666/); | |||||||||
| 108 | } | ||||||||||
| 109 | |||||||||||
| 110 | 24112 | ▶ | if (_is_infinite($value)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 111 | 0 | return 0; | |||||||||
| 112 | } | ||||||||||
| 113 | |||||||||||
| 114 | 24112 | my $cube = $self->{'cube'}; # radix^3 | |||||||||
| 115 | 24112 | my $target = $self->{'target'}; # 666 in radix | |||||||||
| 116 | 24112 | for (;;) { | |||||||||
| 117 | 64109 | ▶ | if (($value % $cube) == $target) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 118 | 137 | return 1; | |||||||||
| 119 | } | ||||||||||
| 120 | 63972 | ▶ | if ($value < $cube) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 121 | 23975 | return 0; | |||||||||
| 122 | } | ||||||||||
| 123 | 39997 | $value = int($value/$radix); | |||||||||
| 124 | } | ||||||||||
| 125 | } | ||||||||||
| 126 | |||||||||||
| 127 | 1 | 1; | |||||||||
| 128 | __END__ | ||||||||||