Math::NumSeq::HappyNumbers -- reaching 1 under repeated sum of squares of digits
use Math::NumSeq::HappyNumbers; my $seq = Math::NumSeq::HappyNumbers->new; my ($i, $value) = $seq->next;
This sequence is the happy numbers which are the numbers eventually reaching 1 on repeatedly taking the sum of the squares of the digits.
1, 7, 10, 13, 19, 23, ... starting i=1
For example 23 is a happy number because the sum of squares of its digits (ie. 2 and 3) is 2*2+3*3=13, then the same sum of squares again 1*1+3*3=10, then 1*1+0*0=1 reaches 1.
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 which reach 1 are called happy numbers.
An optional radix parameter can select a base other than decimal. Base 2 and base 4 are not very interesting since for them every number except 0 is happy.
radix
See "FUNCTIONS" in Math::NumSeq for behaviour common to all sequence classes.
$seq = Math::NumSeq::HappyNumbers->new ()
$seq = Math::NumSeq::HappyNumbers->new (radix => $r)
Create and return a new sequence object.
$bool = $seq->pred($value)
Return true if $value is a happy number, meaning repeated sum of squares of its digits reaches 1.
$value
Math::NumSeq, Math::NumSeq::HappySteps, Math::NumSeq::DigitSum
http://user42.tuxfamily.org/math-numseq/index.html
Copyright 2011, 2012, 2013 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/>.
To install Math::NumSeq, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Math::NumSeq
CPAN shell
perl -MCPAN -e shell install Math::NumSeq
For more information on module installation, please visit the detailed CPAN module installation guide.