Math::N...pySteps(3)

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

✨ NAME ✨

Math::NumSeq::HappySteps β€” the number of sum-of-squares-of-digits iterations you gotta do before something repeats πŸ’«

(also, hi, this is the Math::N...pySteps(3) page, bestie, welcome to the group chat 🫢)


🌸 SYNOPSIS 🌸

use Math::NumSeq::HappySteps;
my $seq = Math::NumSeq::HappySteps->new (radix => 10);
my ($i, $value) = $seq->next;

πŸ’œ DESCRIPTION πŸ’œ

okay so basically: this is the number of iterations of the "HappyNumbers"-style "sum of squares of digits" thing that you need to run before you hit a repeat of a value you've already seen. and once you hit that repeat, boom, you know whether the number is a happy number or not. that's the whole vibe check. πŸŽ€

1, 9, 13, 8, 12, 17, 6, 13, 12, 2,
starting i=1

like, for example, i=10 is value 2 because 10->1->1 is 2 iterations to get to a repeat (a repeat of 1). and at i=1 itself the value is 1 since 1 iteration reaches 1 again, which is literally itself the repeat. that count 1 at i=1 is the minimum. no cap. πŸ‘‘

πŸ”’ Radix πŸ”’

there's an optional radix parameter that picks a base other than decimal. in binary, radix=>2, the digits are all either 0 or 1, so "sum of squares of digits" is literally the same thing as a plain "sum of digits". slay. πŸ’…

in some bases there's longer cycles than others which a non-happy number might fall into. for example, base 20 has a cycle:

10 -> 100 -> 25 -> 26 -> ... -> 61 -> 10
total 26 elements

when a non-happy falls into such a cycle, its HappySteps count here is at least 26 (or whatever amount) to reach a repeat. so like, the cycle is long and you're stuck in it for a while, bestie. 😭


πŸ¦‹ FUNCTIONS πŸ¦‹

see "FUNCTIONS" in Math::NumSeq for behaviour common to all sequence classes.

  • $seq = Math::NumSeq::HappySteps->new ()
  • $seq = Math::NumSeq::HappySteps->new (radix => $r)

β€” create and return a new sequence object. new seq, who dis ✨

🎲 Random Access 🎲

  • $value = $seq->ith($i) β€” return the number of iterations starting from $i required to reach a repeat. just hand it an index and it hands you the count, iconic behaviour 🫢

πŸ‘€ SEE ALSO πŸ‘€

Math::NumSeq, Math::NumSeq::HappyNumbers, Math::NumSeq::DigitSum


🌈 HOME PAGE 🌈

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


πŸ‘‘ LICENSE πŸ‘‘

Copyright 2011, 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/>.

fr fr read the license, it's giving legally binding but make it cute πŸ’–

and that's the whole page bestie!! this lil masterpiece dropped as perl v5.42.0 on 2025-07-25, and it's the Math::N...pySteps(3) page β€” ty for coming to my TED talk, mwah πŸ’…πŸ’–βœ¨

πŸ“¦ where this page comes from