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
|
|
293783
|
use 5.004; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
81
|
|
21
|
2
|
|
|
2
|
|
13
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
94
|
|
22
|
2
|
|
|
2
|
|
22
|
use List::Util 'reduce'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
201
|
|
23
|
|
|
|
|
|
|
|
24
|
2
|
|
|
2
|
|
9
|
use vars '$VERSION', '@ISA'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
105
|
|
25
|
|
|
|
|
|
|
$VERSION = 71; |
26
|
|
|
|
|
|
|
|
27
|
2
|
|
|
2
|
|
651
|
use Math::NumSeq; |
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
48
|
|
28
|
2
|
|
|
2
|
|
594
|
use Math::NumSeq::Base::IterateIth; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
109
|
|
29
|
|
|
|
|
|
|
@ISA = ('Math::NumSeq::Base::IterateIth', |
30
|
|
|
|
|
|
|
'Math::NumSeq'); |
31
|
|
|
|
|
|
|
*_is_infinite = \&Math::NumSeq::_is_infinite; |
32
|
|
|
|
|
|
|
|
33
|
2
|
|
|
2
|
|
593
|
use Math::NumSeq::Repdigits; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
99
|
|
34
|
|
|
|
|
|
|
*_digit_split_lowtohigh = \&Math::NumSeq::Repdigits::_digit_split_lowtohigh; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
2
|
|
|
2
|
|
13
|
use constant name => Math::NumSeq::__('Digit Product'); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
11
|
|
38
|
2
|
|
|
2
|
|
12
|
use constant description => Math::NumSeq::__('Product of digits a given radix.'); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
8
|
|
39
|
2
|
|
|
2
|
|
12
|
use constant i_start => 0; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
106
|
|
40
|
2
|
|
|
2
|
|
12
|
use constant characteristic_smaller => 1; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
113
|
|
41
|
2
|
|
|
2
|
|
11
|
use constant characteristic_increasing => 0; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
86
|
|
42
|
2
|
|
|
2
|
|
12
|
use constant characteristic_integer => 1; |
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
96
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
use Math::NumSeq::Base::Digits |
45
|
2
|
|
|
2
|
|
13
|
'parameter_info_array'; # radix parameter |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
133
|
|
46
|
|
|
|
|
|
|
|
47
|
2
|
|
|
2
|
|
11
|
use constant values_min => 0; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
764
|
|
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
|
12
|
my ($self) = @_; |
65
|
2
|
|
|
|
|
8
|
return $oeis_anum[$self->{'radix'}]; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub ith { |
71
|
588
|
|
|
588
|
1
|
909
|
my ($self, $i) = @_; |
72
|
|
|
|
|
|
|
|
73
|
588
|
50
|
|
|
|
1336
|
if (_is_infinite ($i)) { |
74
|
0
|
|
|
|
|
0
|
return $i; |
75
|
|
|
|
|
|
|
} |
76
|
588
|
100
|
|
|
|
1261
|
if ($i == 0) { |
77
|
10
|
|
|
|
|
39
|
return 0; |
78
|
|
|
|
|
|
|
} |
79
|
578
|
|
|
1039
|
|
2508
|
return reduce {$a * $b} _digit_split_lowtohigh($i, $self->{'radix'}) |
|
1039
|
|
|
|
|
2427
|
|
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub pred { |
83
|
59
|
|
|
59
|
1
|
257
|
my ($self, $value) = @_; |
84
|
59
|
100
|
66
|
|
|
135
|
if (_is_infinite ($value) |
|
|
|
66
|
|
|
|
|
85
|
|
|
|
|
|
|
|| $value < 0 |
86
|
|
|
|
|
|
|
|| $value != int($value)) { |
87
|
3
|
|
|
|
|
15
|
return 0; |
88
|
|
|
|
|
|
|
} |
89
|
56
|
|
|
|
|
175
|
my $radix = $self->{'radix'}; |
90
|
56
|
|
100
|
|
|
229
|
for (my $i = 2; $i < $radix && $value > 1; $i+=1+($i!=2)) { |
91
|
33
|
|
|
|
|
100
|
until ($value % $i) { |
92
|
36
|
|
|
|
|
134
|
$value = int($value/$i); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
} |
95
|
56
|
|
|
|
|
149
|
return ($value <= 1); # remainder |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
1; |
99
|
|
|
|
|
|
|
__END__ |