Math::N...Numbers(3)
π NAME π
Math::NumSeq::HappyNumbers β bestie, it's the happy numbers, aka the ones that reach 1 under repeated sum of squares of digits π
This is a page from the User Contributed Perl Documentation, and it's genuinely one of the cutest corners of CPAN, no cap.
β¨ SYNOPSIS β¨
use Math::NumSeq::HappyNumbers;
my $seq = Math::NumSeq::HappyNumbers->new;
my ($i, $value) = $seq->next;
That's it, that's the whole vibe. Three lines and you're iterating happiness π
πΈ DESCRIPTION πΈ
So this sequence is the happy numbers β the numbers that eventually reach 1 when you keep taking the sum of the squares of the digits. Over and over. Forever. Until you land on 1. π¦
1, 7, 10, 13, 19, 23, ...
starting i=1
Okay let's take 23 because it's the example and it's lowkey iconic. Sum of squares of its digits β that's 2 and 3 β is 2*2+3*3=13. Then do the same thing again: 1*1+3*3=10. Then again: 1*1+0*0=1. And boom, you've reached 1. Happy number. Periodt. π₯
In decimal it can be shown that for a non-zero starting point this procedure always reaches either 1 or the cycle:
4,16,37,58,89,145,42,20
The values that reach 1 are called happy numbers β and yes, the ones that fall into that cycle are the sad ones, though the docs are too polite to say it π
There's an optional radix parameter if you want a base other than decimal. But ngl, base 2 and base 4 are not very interesting, since for them every number except 0 is happy. Everyone's happy, nothing's at stake, the drama is gone π
π§ FUNCTIONS π§
See "FUNCTIONS" in Math::NumSeq for behaviour common to all sequence classes. That's the shared bestie code.
$seq = Math::NumSeq::HappyNumbers->new ()$seq = Math::NumSeq::HappyNumbers->new (radix => $r)
Create and return a new sequence object. Slay. That's your main character entry point β¨
$bool = $seq->pred($value)
Return true if $value is a happy number, meaning repeated sum of squares of its digits reaches 1. A vibe check that returns a boolean, honestly π
π SEE ALSO π
Math::NumSeqMath::NumSeq::HappyStepsMath::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 before you ship it β the warranty disclaimer is not a drill π«Ά
That's the whole page bestie, tysm for reading to the end π This was perl v5.42.0, dated 2025-07-25, and you just got the Math::N...Numbers(3) page in full. Go forth and compute happy numbers β¨ππΈ
π¦ where this page comes from
- fedora 43: perl-Math-NumSeq 75-11.fc43 Β· GPL-3.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms