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
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
package Math::NumSeq::DigitProduct; |
20
|
2
|
|
|
2
|
|
6168
|
use 5.004; |
|
2
|
|
|
|
|
7
|
|
21
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
53
|
|
22
|
2
|
|
|
2
|
|
10
|
use List::Util 'reduce'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
150
|
|
23
|
|
|
|
|
|
|
|
24
|
2
|
|
|
2
|
|
10
|
use vars '$VERSION', '@ISA'; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
119
|
|
25
|
|
|
|
|
|
|
$VERSION = 72; |
26
|
|
|
|
|
|
|
|
27
|
2
|
|
|
2
|
|
354
|
use Math::NumSeq; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
47
|
|
28
|
2
|
|
|
2
|
|
368
|
use Math::NumSeq::Base::IterateIth; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
100
|
|
29
|
|
|
|
|
|
|
@ISA = ('Math::NumSeq::Base::IterateIth', |
30
|
|
|
|
|
|
|
'Math::NumSeq'); |
31
|
|
|
|
|
|
|
*_is_infinite = \&Math::NumSeq::_is_infinite; |
32
|
|
|
|
|
|
|
|
33
|
2
|
|
|
2
|
|
335
|
use Math::NumSeq::Repdigits; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
103
|
|
34
|
|
|
|
|
|
|
*_digit_split_lowtohigh = \&Math::NumSeq::Repdigits::_digit_split_lowtohigh; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
2
|
|
|
2
|
|
11
|
use constant name => Math::NumSeq::__('Digit Product'); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
8
|
|
38
|
2
|
|
|
2
|
|
11
|
use constant description => Math::NumSeq::__('Product of digits a given radix.'); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
6
|
|
39
|
2
|
|
|
2
|
|
10
|
use constant i_start => 0; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
872
|
|
40
|
2
|
|
|
2
|
|
10
|
use constant characteristic_smaller => 1; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
107
|
|
41
|
2
|
|
|
2
|
|
9
|
use constant characteristic_increasing => 0; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
104
|
|
42
|
2
|
|
|
2
|
|
9
|
use constant characteristic_integer => 1; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
97
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
use Math::NumSeq::Base::Digits |
45
|
2
|
|
|
2
|
|
8
|
'parameter_info_array'; # radix parameter |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
106
|
|
46
|
|
|
|
|
|
|
|
47
|
2
|
|
|
2
|
|
9
|
use constant values_min => 0; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
648
|
|
48
|
|
|
|
|
|
|
sub values_max { |
49
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
50
|
0
|
0
|
|
|
|
0
|
return ($self->{'radix'} == 2 ? 1 : undef); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
54
|
|
|
|
|
|
|
# apparently no ternary or base 4 ... |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
my @oeis_anum; |
57
|
|
|
|
|
|
|
# A036987 binary, being 0 if any 0-bits and 1 if all 1-bits, |
58
|
|
|
|
|
|
|
# but it takes i=0 to be an empty product value=1 |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
$oeis_anum[10] = 'A007954'; # 10 decimal, starting from 0 |
61
|
|
|
|
|
|
|
# OEIS-Catalogue: A007954 radix=10 |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub oeis_anum { |
64
|
2
|
|
|
2
|
1
|
8
|
my ($self) = @_; |
65
|
2
|
|
|
|
|
3
|
return $oeis_anum[$self->{'radix'}]; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub ith { |
71
|
588
|
|
|
588
|
1
|
478
|
my ($self, $i) = @_; |
72
|
|
|
|
|
|
|
|
73
|
588
|
50
|
|
|
|
731
|
if (_is_infinite ($i)) { |
74
|
0
|
|
|
|
|
0
|
return $i; |
75
|
|
|
|
|
|
|
} |
76
|
588
|
100
|
|
|
|
728
|
if ($i == 0) { |
77
|
10
|
|
|
|
|
23
|
return 0; |
78
|
|
|
|
|
|
|
} |
79
|
578
|
|
|
1039
|
|
1324
|
return reduce {$a * $b} _digit_split_lowtohigh($i, $self->{'radix'}) |
|
1039
|
|
|
|
|
1591
|
|
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub pred { |
83
|
59
|
|
|
59
|
1
|
149
|
my ($self, $value) = @_; |
84
|
59
|
100
|
66
|
|
|
72
|
if (_is_infinite ($value) |
|
|
|
66
|
|
|
|
|
85
|
|
|
|
|
|
|
|| $value < 0 |
86
|
|
|
|
|
|
|
|| $value != int($value)) { |
87
|
3
|
|
|
|
|
6
|
return 0; |
88
|
|
|
|
|
|
|
} |
89
|
56
|
|
|
|
|
62
|
my $radix = $self->{'radix'}; |
90
|
56
|
|
100
|
|
|
152
|
for (my $i = 2; $i < $radix && $value > 1; $i+=1+($i!=2)) { |
91
|
33
|
|
|
|
|
68
|
until ($value % $i) { |
92
|
36
|
|
|
|
|
87
|
$value = int($value/$i); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
} |
95
|
56
|
|
|
|
|
76
|
return ($value <= 1); # remainder |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
1; |
99
|
|
|
|
|
|
|
__END__ |