Math::NumSeq::CollatzSteps -- steps in the "3n+1" problem
use Math::NumSeq::CollatzSteps; my $seq = Math::NumSeq::CollatzSteps->new; my ($i, $value) = $seq->next;
The number of steps it takes to reach 1 by the Collatz "3n+1" problem,
n -> / 3n+1 if n odd \ n/2 if n even
It's conjectured that any starting n will always eventually reduce to 1, so the number of steps is finite. There's no limit in the code on how many steps counted. Math::BigInt is used if 3n+1 steps go past the usual scalar integer limit.
Math::BigInt
See "FUNCTIONS" in Math::NumSeq for behaviour common to all sequence classes.
$seq = Math::NumSeq::CollatzSteps->new ()
$seq = Math::NumSeq::CollatzSteps->new (step_type => 'down')
Create and return a new sequence object.
The optional step_type parameter (a string) selects between
step_type
"up" upward steps 3n+1 "down" downward steps n/2 "both" both up and down, which is the default
$value = $seq->ith($i)
Return the number of steps to take $i down to 1.
$i
$bool = $seq->pred($value)
Return true if $value occurs as a step count. This is simply $value >= 0.
$value
$value >= 0
Math::NumSeq, Math::NumSeq::JugglerSteps, Math::NumSeq::ReverseAddSteps
http://user42.tuxfamily.org/math-numseq/index.html
Copyright 2011, 2012 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/>.
To install Math::NumSeq, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Math::NumSeq
CPAN shell
perl -MCPAN -e shell install Math::NumSeq
For more information on module installation, please visit the detailed CPAN module installation guide.