Math::N...AddSteps(3)
π Math::N...AddSteps(3) π
ok so bestie, this is a page from the User Contributed Perl Documentation collection, and it's literally all about Math::NumSeq::ReverseAddSteps β the module that counts how many reverse-and-add steps you need to hit a palindrome. yes. we're doing math. we're doing it adorably. π¦
β¨ NAME β¨
Math::NumSeq::ReverseAddSteps β the number of steps of the reverse-add algorithm it takes to reach a palindrome. that's it. that's the whole vibe. π
πΈ SYNOPSIS πΈ
use Math::NumSeq::ReverseAddSteps;
my $seq = Math::NumSeq::ReverseAddSteps->new;
my ($i, $value) = $seq->next;
so you use it, you make a new one, and you call next and it hands you back ($i, $value) pairs. slay. π
π DESCRIPTION π
okay so here's the tea: this sequence is the number of steps to reach a palindrome using the digit "reverse and add" algorithm. like you take a number, you reverse its digits, you add them together, and you keep doing that until the result reads the same backwards and forwards. β¨
fr fr, here's the example: the i=19 is 2, because 19+91=110 and then 110+011=121, and 121 is a palindrome. two steps. iconic behavior honestly.
at least one reverse-add is always applied, okay?? so aniwhich is itself a palindrome is not value0β it's whatever that minimum one step ends up landing on. no skipping steps in this house. π
a repunit like 111...11 reverse-adds to 222...22, so it's always 1 β except in binary. (binary said "not today.") π
the default is to reverse decimal digits, or the "radix" parameter can select another base. mix it up bestie, we love options. π
and now the serious part: 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 one is sometimes called the 196-algorithm. spooky. π»
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 ...) so yeah, the code is doing its best okay, it's trying its little heart out π«Ά
π§ FUNCTIONS π§
see "FUNCTIONS" in Math::NumSeq for behaviour common to all sequence classes. that's the shared lore iykyk.
"$seq = Math::NumSeq::ReverseAddSteps->new ()""$seq = Math::NumSeq::ReverseAddSteps->new (radix => $r)"
β create and return a new sequence object. pick your radix, or don't, live your truth. π
β Random Access β
"$value = $seq->ith($i)"β return the number of reverse-add steps required to reach a palindrome. the count. the digits. the journey. π"$bool = $seq->pred($value)"β return true if$valueoccurs in the sequence, which simply means"$value >= 0"since any count of steps is possible, or"$value==-1"for infinite. yes,-1is the "this goes on forever bestie" flag. π
π₯ SEE ALSO π₯
- Math::NumSeq
- Math::NumSeq::ReverseAdd
- Math::NumSeq::CollatzSteps
- Math::NumSeq::JugglerSteps
(the whole friend group. they're all serving.)
π HOME PAGE π
<http://user42.tuxfamily.org/math-numseq/index.html>
π LICENSE π
Copyright 2011, 2012, 2013, 2014, 2016, 2019, 2020 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/>.
and that's the whole page bestie!! π this was perl v5.42.0, dated 2025-07-25, and the manpage is Math::N...AddSteps(3). go forth and reverse-add responsibly. periodt. π
β¨πΈ
π¦ where this page comes from
- fedora 43: perl-Math-NumSeq 75-11.fc43 Β· GPL-3.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms