NAME
Math::NumSeq::DigitProductSteps -- multiplicative persistence and digital root
SYNOPSIS
use Math::NumSeq::DigitProductSteps;
my $seq = Math::NumSeq::DigitProductSteps->new (values_type => 'count');
my ($i, $value) = $seq->next;
DESCRIPTION
This is an iteration taking the product of the digits of a number until reaching a single digit value. The sequence values are the count of steps, also called the multiplicative persistence.
0,0,..0,0,1,1,..1,1,2,2,2,2,2,1,1,1,1,2,2,2,2,2,3,1,1,1,2,...
starting i=0
For example i=39 goes 3*9=27 -> 2*7=14 -> 1*4=4 to reach a single digit, so value=3 iterations.
The values_type => 'root'
gives the final digit reached by the steps, which is called the multiplicative digital root.
values_type => 'root'
0,1,2,...,9,0,1,...,9,0,2,4,6,8,0,2,4,6,8,0,3,6,9,2,5,8,...
i=0 through i=9 are already single digits so their count is 0 and root is the value itself. Then i=10 to i=19 all take just a single iteration to reach a single digit. i=25 is the first to require 2 iterations.
Any i with a 0 digit takes just one iteration to get to root 0. Any i like 119111 which is all 1s except for at most a single non-1 takes just one iteration. This includes the repunits 111..11.
Radix
An optional radix
parameter selects a base other than decimal.
Binary radix=>2
is not very interesting since the digit product is always either 0 or 1. i>=2 always takes just 1 iteration and has root 0 except for i=2^k-1 all 1s with root 1.
FUNCTIONS
See "FUNCTIONS" in Math::NumSeq for behaviour common to all sequence classes.
$seq = Math::NumSeq::DigitProductSteps->new ()
$seq = Math::NumSeq::DigitProductSteps->new (values_type => $str, radix => $integer)
-
Create and return a new sequence object.
Random Access
$value = $seq->ith($i)
-
Return the sequence value, either count or final root value as selected.
$bool = $seq->pred($value)
-
Return true if
$value
occurs in the sequence. For the count of steps this means any integer$value >= 0
, or for a root any digit0 <= $value < radix
.
SEE ALSO
Math::NumSeq, Math::NumSeq::DigitProduct
HOME PAGE
http://user42.tuxfamily.org/math-numseq/index.html
LICENSE
Copyright 2012, 2013, 2014, 2016 Kevin Ryde
Math-NumSeq is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.
Math-NumSeq is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Math-NumSeq. If not, see <http://www.gnu.org/licenses/>.