++ed by:
Kevin Ryde
and 1 contributors

# NAME

Math::NumSeq::HappySteps -- number of sum of squares of digits iterations to reach a repeat

# SYNOPSIS

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

# DESCRIPTION

This is the number of iterations of the `HappyNumbers` style "sum of squares of digits" is required to reach a repeat of a value seen before, and therefore to establish whether a number is a happy number or not.

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

For example i=10 is value 2 because 10->1->1 is 2 iterations to get to a repeat (a repeat of 1). At i=1 itself the value is 1 since 1 iteration reaches 1 again which is itself the repeat. That count 1 at i=1 is the minimum.

An optional `radix` parameter selects a base other than decimal. In binary `radix=>2` the digits are all either 0 or 1 so "sum of squares of digits" is the same as a plain "sum of digits".

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.

# 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.

## Random Access

`\$value = \$seq->ith(\$i)`

Return the number of iterations starting from `\$i` required to reach a repeat.