| 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 | |||||||||||||||||||||
| 19 | # Fractal turn sequence: | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | # "Infinite streams", Jorg Endrullis, Clemens Grabmayer, Dimitri Hendriks, | ||||||||||||||||||||
| 22 | # Jan Willem Klop, www.phil.uu.nl/~clemens/linkedfiles/NVTI2009.pdf | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | package Math::NumSeq::MephistoWaltz; | ||||||||||||||||||||
| 26 | 1 | ▶ | use 5.004; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 27 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | 1 | ▶ | use vars '$VERSION', '@ISA'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 30 | 1 | $VERSION = 75; | |||||||||||||||||||
| 31 | 1 | ▶ | use Math::NumSeq; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 32 | 1 | @ISA = ('Math::NumSeq'); | |||||||||||||||||||
| 33 | 1 | *_is_infinite = \&Math::NumSeq::_is_infinite; | |||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | # uncomment this to run the ### lines | ||||||||||||||||||||
| 36 | #use Smart::Comments; | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | # use constant name => Math::NumSeq::__('Mephisto Waltz'); | ||||||||||||||||||||
| 40 | 1 | ▶ | use constant description => Math::NumSeq::__('Mephisto waltz sequence.'); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 41 | 1 | ▶ | use constant i_start => 0; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 42 | 1 | ▶ | use constant values_min => 0; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 43 | 1 | ▶ | use constant values_max => 1; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 44 | 1 | ▶ | use constant characteristic_integer => 1; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | # cf A189658 - positions of 0 | ||||||||||||||||||||
| 47 | # A189659 - positions of 1 | ||||||||||||||||||||
| 48 | # A189660 - cumulative 0/1 | ||||||||||||||||||||
| 49 | # A156595 - xor diffs, OFFSET=0 so a(n) = m(n) xor m(n+1) | ||||||||||||||||||||
| 50 | # | ||||||||||||||||||||
| 51 | 1 | ▶ | use constant oeis_anum => 'A064990'; # mephisto waltz 0/1 values | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 2 | ▶ | sub rewind { | ||||||||||||||||||
|
Subroutine
rewind: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 54 | 2 | my ($self) = @_; | |||||||||||||||||||
| 55 | 2 | $self->{'i'} = $self->i_start; | |||||||||||||||||||
| 56 | 2 | $self->{'value'} = 1; | |||||||||||||||||||
| 57 | 2 | $self->{'low'} = -1; | |||||||||||||||||||
| 58 | 2 | $self->{'digits'} = []; | |||||||||||||||||||
| 59 | } | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 1 | my @table = (0,0,1, 0,0,1, 1,1,0, | |||||||||||||||||||
| 62 | 0,0,1, 0,0,1, 1,1,0, | ||||||||||||||||||||
| 63 | 1,1,0, 1,1,0, 0,0,1); | ||||||||||||||||||||
| 64 | 1 | my @delta = (map {$table[$_]^$table[($_+26)%27]} 0 .. $#table); | |||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 2187 | ▶ | sub next { | ||||||||||||||||||
|
Subroutine
next: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||
| 67 | 2187 | my ($self) = @_; | |||||||||||||||||||
| 68 | ### MephistoWaltz next(): $self->{'i'} | ||||||||||||||||||||
| 69 | ### at: "low=$self->{'low'} value=$self->{'value'}" | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 2187 | my $low; | |||||||||||||||||||
| 72 | 2187 | ▶ | if (($low = ++$self->{'low'}) >= 27) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 73 | 80 | $low = $self->{'low'} = 0; | |||||||||||||||||||
| 74 | 80 | my $i = 0; | |||||||||||||||||||
| 75 | 80 | for (;;) { | |||||||||||||||||||
| 76 | 82 | my $digit = ++$self->{'digits'}->[$i]; | |||||||||||||||||||
| 77 | ### carry to digit: $digit | ||||||||||||||||||||
| 78 | 82 | ▶ | if ($digit >= 27) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 79 | 2 | $self->{'digits'}->[$i++] = 0; | |||||||||||||||||||
| 80 | 2 | $self->{'value'} ^= 1; # three 2s have become 0s | |||||||||||||||||||
| 81 | } else { | ||||||||||||||||||||
| 82 | 80 | $self->{'value'} ^= $delta[$digit]; | |||||||||||||||||||
| 83 | 80 | last; | |||||||||||||||||||
| 84 | } | ||||||||||||||||||||
| 85 | } | ||||||||||||||||||||
| 86 | } | ||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | ### apply: "low=$low delta=$delta[$low]" | ||||||||||||||||||||
| 89 | return ($self->{'i'}++, | ||||||||||||||||||||
| 90 | 2187 | ($self->{'value'} ^= $delta[$low])); | |||||||||||||||||||
| 91 | } | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | 2673 | ▶ | sub ith { | ||||||||||||||||||
|
Subroutine
ith: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||
| 94 | 2673 | my ($self, $i) = @_; | |||||||||||||||||||
| 95 | ### ith(): $i | ||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | 2673 | ▶ | if (_is_infinite($i)) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 98 | 0 | return $i; | |||||||||||||||||||
| 99 | } | ||||||||||||||||||||
| 100 | 2673 | my $ret = 0; | |||||||||||||||||||
| 101 | 2673 | ▶ | while ($i) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 102 | 6720 | $ret ^= $table[$i % 27]; | |||||||||||||||||||
| 103 | 6720 | $i = int($i/27); | |||||||||||||||||||
| 104 | } | ||||||||||||||||||||
| 105 | 2673 | return $ret; | |||||||||||||||||||
| 106 | } | ||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | 0 | ▶ | sub pred { | ||||||||||||||||||
|
Subroutine
pred: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 109 | 0 | my ($self, $value) = @_; | |||||||||||||||||||
| 110 | 0 | ▶ | return ($value == 0 || $value == 1); | ||||||||||||||||||
|
Condition0%0/3
$value == 0 || $value == 1
MC/DC0%0/2
$value == 0 || $value == 1
$value == 0
$value == 1
Truth table0%0/3
A || B
A= $value == 0B= $value == 1
| |||||||||||||||||||||
| 111 | } | ||||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | 1 | 1; | |||||||||||||||||||
| 114 | __END__ | ||||||||||||||||||||