Kevin Ryde > Math-NumSeq > Math::NumSeq::ReverseAddSteps

Download:
Math-NumSeq-71.tar.gz

Dependencies

Annotate this POD

Website

CPAN RT

Open  2
View/Report Bugs
Module Version: 71   Source  

NAME ^

Math::NumSeq::ReverseAddSteps -- steps of the reverse-add algorithm to reach palindrome

SYNOPSIS ^

 use Math::NumSeq::ReverseAddSteps;
 my $seq = Math::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 is a palindrome.

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 like 111...11 reverse-adds to 222...22 so it's always 1 (except in binary).

The default is to reverse decimal digits, 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 that is sometimes called the 196-algorithm). In the current code a hard limit of 100 is imposed on the search - perhaps something better is possible. (Some binary infinites can be recognised from their bit pattern ...)

FUNCTIONS ^

See "FUNCTIONS" in Math::NumSeq for behaviour common to all sequence classes.

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

Create and return a new sequence object.

Random Access

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

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

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

Return true if $value occurs in the sequence, which simply means $value >= 0 since any count of steps is possible, or $value==-1 for infinite.

SEE ALSO ^

Math::NumSeq, Math::NumSeq::ReverseAdd, Math::NumSeq::CollatzSteps, Math::NumSeq::JugglerSteps

HOME PAGE ^

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

LICENSE ^

Copyright 2011, 2012, 2013, 2014 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/>.

syntax highlighting: