search.cpan.org is shutting down
Kevin Ryde > Math-NumSeq > Math::NumSeq::HappyNumbers

Math-NumSeq-72.tar.gz

Dependencies

Annotate this POD

Website

CPAN RT

 Open 0
View/Report Bugs
Module Version: 72

NAME

Math::NumSeq::HappyNumbers -- reaching 1 under repeated sum of squares of digits

SYNOPSIS

``` use Math::NumSeq::HappyNumbers;
my \$seq = Math::NumSeq::HappyNumbers->new;
my (\$i, \$value) = \$seq->next;```

DESCRIPTION

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.

FUNCTIONS

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.

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