Math::N...uctSteps(3)

πŸ“¦
version 75 Β· 2 versions
, in fedora 43

✨ NAME ✨

Math::NumSeq::DigitProductSteps β€” multiplicative persistence and digital root πŸ’…

okay so bestie, this is a Perl thing from the User Contributed Perl Documentation, and it's genuinely so cute once you get it, i promise 🫢


🌸 SYNOPSIS 🌸

use Math::NumSeq::DigitProductSteps;
my $seq = Math::NumSeq::DigitProductSteps->new (values_type => 'count');
my ($i, $value) = $seq->next;

that's it. that's the whole vibe check. make a sequence object, call next on it, get back an index and a value. iconic ✨


πŸ¦‹ DESCRIPTION πŸ¦‹

so what this thing does is it keeps multiplying the digits of a number together until you're left with a single digit. and the sequence values? they're the count of steps it took to get there. that count has a fancy name: 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

like, take i=39. it goes 3*9=27 β†’ 2*7=14 β†’ 1*4=4 to reach a single digit, so the value is 3 iterations. three whole steps, main character energy πŸ’…

then if you pass values_type => 'root' you get the final digit you landed on instead, 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,...

and here's the tea:

  • i=0 through i=9 are already single digits, so their count is 0 and their root is just the value itself. no work needed, slay πŸ’–
  • i=10 to i=19 all take just a single iteration to reach a single digit.
  • i=25 is the first one that needs 2 iterations. not me being dramatic about i=25 but it IS the first ok 😭

more lore: any i with a 0 digit takes just one iteration to get to root 0. and any i like 119111 β€” all 1s except for at most a single non-1 β€” also takes just one iteration. this includes the repunits 111..11 ✨ (yes bestie, repunits are a real word and they're kinda iconic)

🌟 Radix 🌟

there's an optional radix parameter that picks a base other than decimal, if you're feeling spicy 🌢️

binary radix=>2 is not very interesting tho, sorry β€” 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 which is all 1s and has root 1. that's the whole binary situation. lowkey uneventful but we respect it 🫑


πŸ’– FUNCTIONS πŸ’–

peep "FUNCTIONS" in Math::NumSeq for the behaviour that's common to all sequence classes, bestie β€” this page is just the special stuff πŸŽ€

  • $seq = Math::NumSeq::DigitProductSteps->new ()
  • $seq = Math::NumSeq::DigitProductSteps->new (values_type => $str, radix => $integer)

create and return a brand new sequence object. new object, new era, periodt ✨

πŸŽ€ Random Access πŸŽ€

  • $value = $seq->ith($i) β€” return the sequence value, either the count or the final root value, whichever you selected. your pick, your power πŸ’…
  • $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 digit "0 <= $value < radix". simple as that 🫢

πŸ‘€ SEE ALSO πŸ‘€

  • Math::NumSeq
  • Math::NumSeq::DigitProduct

go read those too, i'm obsessed with a well-organized module family πŸ’œ


🌐 HOME PAGE 🌐

<http://user42.tuxfamily.org/math-numseq/index.html>


πŸ“œ LICENSE πŸ“œ

Copyright 2012, 2013, 2014, 2016, 2019, 2020 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/>.

bestie that warranty disclaimer is doing the MOST and honestly? respect. no cap, read your licenses πŸ’€

and that's the whole page!! this was Math::N...uctSteps(3) from perl v5.42.0, dated 2025-07-25 β€” mwah, ty for reading, go multiply some digits, ily πŸ«ΆπŸ’–βœ¨

πŸ“¦ where this page comes from