NAME

App::MathImage::NumSeq::ReverseAddSteps -- steps of the reverse-add algorithm

SYNOPSIS

use App::MathImage::NumSeq::ReverseAddSteps;
my $seq = App::MathImage::NumSeq::ReverseAddSteps->new;
my ($i, $value) = $seq->next;

DESCRIPTION

The number of steps to reach a palindrome by the digit "reverse and add" algorithm. For example the i=19 is 2 because 19+91=110 then 110+011=121.

At least one reverse-add is applied, so an i which is itself a palindrome is not value 0, but wherever that minimum one step might end up. A repunit palindrome like 111...11 reverse-adds to 222...22 so it's always 1 (except in binary).

The default is to reverse digits in decimal, or the radix parameter can select another base.

The number of steps can be infinite. In binary for example 3 = 11 binary never reaches a palindrome, and in decimal it's conjectured that 196 doesn't (and from which this is sometimes called the 196-algorithm). In the current code a limit of 50 is imposed on the search.

FUNCTIONS

$seq = App::MathImage::NumSeq::ReverseAddSteps->new ()
$seq = App::MathImage::NumSeq::ReverseAddSteps->new (radix => $r)

Create and return a new sequence object.

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

Return the number of reverse-add steps required to reach a palindrome.

$bool = $seq->pred($value)

Return true if $value >= 0, since any count of steps is possible.

SEE ALSO

Math::NumSeq