| 1 | # Copyright 2012, 2015, 2020 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 <http://www.gnu.org/licenses/>. | ||||||||||||
| 17 | |||||||||||||
| 18 | |||||||||||||
| 19 | # cf A000787 - strobogramatic rotate 180 | ||||||||||||
| 20 | # A007284 - symmetric flipped across horizontal line, digits 0,1,3,8 only | ||||||||||||
| 21 | # A234691 - segments as bits | ||||||||||||
| 22 | # A234692 - segments as bits | ||||||||||||
| 23 | |||||||||||||
| 24 | package Math::NumSeq::SevenSegments; | ||||||||||||
| 25 | 1 | ▶ | use 5.004; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 26 | 1 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 27 | 1 | ▶ | use List::Util 'min','max','sum'; | ||||||||||
|
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 = 4; | |||||||||||
| 31 | 1 | ▶ | use Math::NumSeq; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 32 | 1 | ▶ | use Math::NumSeq::Base::IterateIth; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 33 | 1 | @ISA = ('Math::NumSeq::Base::IterateIth', | |||||||||||
| 34 | 'Math::NumSeq'); | ||||||||||||
| 35 | 1 | *_is_infinite = \&Math::NumSeq::_is_infinite; | |||||||||||
| 36 | |||||||||||||
| 37 | 1 | ▶ | use Math::NumSeq::Repdigits; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 38 | 1 | *_digit_split_lowtohigh = \&Math::NumSeq::Repdigits::_digit_split_lowtohigh; | |||||||||||
| 39 | |||||||||||||
| 40 | # uncomment this to run the ### lines | ||||||||||||
| 41 | # use Smart::Comments; | ||||||||||||
| 42 | |||||||||||||
| 43 | |||||||||||||
| 44 | # use constant name => Math::NumSeq::__('...'); | ||||||||||||
| 45 | 1 | ▶ | use constant description => Math::NumSeq::__('Number of segments for i written in 7-segment calculator display.'); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 46 | 1 | ▶ | use constant default_i_start => 0; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 47 | 1 | ▶ | use constant values_min => 2; # "1" using 2 segments | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 48 | 1 | ▶ | use constant characteristic_count => 1; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 49 | 1 | ▶ | use constant characteristic_smaller => 1; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 50 | 1 | ▶ | use constant characteristic_integer => 1; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 51 | 1 | ▶ | use constant parameter_info_array => | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 52 | [ | ||||||||||||
| 53 | { | ||||||||||||
| 54 | name => 'six', | ||||||||||||
| 55 | display => ('Six'), | ||||||||||||
| 56 | type => 'integer', | ||||||||||||
| 57 | default => 6, | ||||||||||||
| 58 | minimum => 5, | ||||||||||||
| 59 | maximum => 6, | ||||||||||||
| 60 | description => ('How many segments to count for "6".'), | ||||||||||||
| 61 | }, | ||||||||||||
| 62 | { | ||||||||||||
| 63 | name => 'seven', | ||||||||||||
| 64 | display => ('Seven'), | ||||||||||||
| 65 | type => 'integer', | ||||||||||||
| 66 | default => 3, | ||||||||||||
| 67 | minimum => 3, | ||||||||||||
| 68 | maximum => 4, | ||||||||||||
| 69 | description => ('How many segments to count for "7".'), | ||||||||||||
| 70 | }, | ||||||||||||
| 71 | { | ||||||||||||
| 72 | name => 'nine', | ||||||||||||
| 73 | display => ('Nine'), | ||||||||||||
| 74 | type => 'integer', | ||||||||||||
| 75 | default => 5, | ||||||||||||
| 76 | minimum => 5, | ||||||||||||
| 77 | maximum => 6, | ||||||||||||
| 78 | description => ('How many segments to count for "9".'), | ||||||||||||
| 79 | }, | ||||||||||||
| 80 | 1 | ]; | |||||||||||
| 81 | |||||||||||||
| 82 | #------------------------------------------------------------------------------ | ||||||||||||
| 83 | |||||||||||||
| 84 | # 6 choice of --- | ||||||||||||
| 85 | # | | | ||||||||||||
| 86 | # --- --- | ||||||||||||
| 87 | # | | | | | ||||||||||||
| 88 | # --- --- | ||||||||||||
| 89 | # | ||||||||||||
| 90 | # 7 choice of --- --- | ||||||||||||
| 91 | # | | | | ||||||||||||
| 92 | # | ||||||||||||
| 93 | # | | | ||||||||||||
| 94 | # | ||||||||||||
| 95 | # 9 choice of --- --- | ||||||||||||
| 96 | # | | | | | ||||||||||||
| 97 | # --- --- | ||||||||||||
| 98 | # | | | ||||||||||||
| 99 | # --- | ||||||||||||
| 100 | # | ||||||||||||
| 101 | # 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | ||||||||||||
| 102 | # A063720 6, 2, 5, 5, 4, 5, 5, 3, 7, 5, 8, 4, 7, 7, 6, 7, 7, 5, 9, 7, 11, 7, 10 | ||||||||||||
| 103 | # A006942 6, 2, 5, 5, 4, 5, 6, 3, 7, 6, 8, 4, 7, 7, 6, 7, 8, 5, 9, 8, 11, 7, 10 | ||||||||||||
| 104 | # A074458 6, 2, 5, 5, 4, 5, 6, 4, 7, 5 | ||||||||||||
| 105 | # A010371 6, 2, 5, 5, 4, 5, 6, 4, 7, 6, 8, 4, 7, 7, 6, 7, 8, 6, 9, 8, 11, 7, 10 | ||||||||||||
| 106 | # A277116 ... | ||||||||||||
| 107 | |||||||||||||
| 108 | 1 | my %oeis_anum = ('5,3,5' => 'A063720', | |||||||||||
| 109 | '6,3,6' => 'A006942', | ||||||||||||
| 110 | '6,4,5' => 'A074458', | ||||||||||||
| 111 | '6,4,6' => 'A010371', | ||||||||||||
| 112 | '6,3,5' => 'A277116', | ||||||||||||
| 113 | ); | ||||||||||||
| 114 | 0 | ▶ | sub oeis_anum { | ||||||||||
|
Subroutine
oeis_anum: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 115 | 0 | my ($self) = @_; | |||||||||||
| 116 | 0 | my $digit_segments = $self->{'digit_segments'}; | |||||||||||
| 117 | 0 | return $oeis_anum{join(',',@{$digit_segments}{'6','7','9'})}; # hash slice | |||||||||||
| 118 | } | ||||||||||||
| 119 | |||||||||||||
| 120 | #------------------------------------------------------------------------------ | ||||||||||||
| 121 | |||||||||||||
| 122 | 2 | ▶ | sub new { | ||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 123 | 2 | my $self = shift->SUPER::new(@_); | |||||||||||
| 124 | |||||||||||||
| 125 | ### $self | ||||||||||||
| 126 | $self->{'digit_segments'} = { 0 => 6, | ||||||||||||
| 127 | 1 => 2, | ||||||||||||
| 128 | 2 => 5, | ||||||||||||
| 129 | 3 => 5, | ||||||||||||
| 130 | 4 => 4, | ||||||||||||
| 131 | 5 => 5, | ||||||||||||
| 132 | 6 => $self->{'six'}, | ||||||||||||
| 133 | 7 => $self->{'seven'}, | ||||||||||||
| 134 | 8 => 7, | ||||||||||||
| 135 | 2 | 9 => $self->{'nine'}, | |||||||||||
| 136 | '-' => 1, # secret support for negatives | ||||||||||||
| 137 | }; | ||||||||||||
| 138 | 2 | return $self; | |||||||||||
| 139 | } | ||||||||||||
| 140 | |||||||||||||
| 141 | 109 | ▶ | sub ith { | ||||||||||
|
Subroutine
ith: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||
| 142 | 109 | my ($self, $i) = @_; | |||||||||||
| 143 | ### SevenSegments ith(): "$i" | ||||||||||||
| 144 | |||||||||||||
| 145 | 109 | ▶ | if (_is_infinite($i)) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 146 | 0 | return undef; | |||||||||||
| 147 | } | ||||||||||||
| 148 | 109 | my $digit_segments = $self->{'digit_segments'}; | |||||||||||
| 149 | 109 | ▶ | return sum (0, map {$digit_segments->{$_}||0} split(//,$i)); | ||||||||||
|
Condition100%2/2
$digit_segments->{$_} || 0
MC/DC100%1/1
$digit_segments->{$_} || 0
$digit_segments->{$_}
Truth table100%2/2
A
A= $digit_segments->{$_}
| |||||||||||||
| 150 | } | ||||||||||||
| 151 | |||||||||||||
| 152 | 1 | 1; | |||||||||||
| 153 | __END__ | ||||||||||||