NAME
Math::NumSeq::Kolakoski -- sequence of 1s and 2s its own run lengths
SYNOPSIS
use Math::NumSeq::Kolakoski;
my $seq = Math::NumSeq::Kolakoski->new;
my ($i, $value) = $seq->next;
DESCRIPTION
The Kolakoski sequence is
i = 1 2 3 4 5 6 7 8 9
value = 1, 2, 2, 1, 1, 2, 1, 2, 2, ... (OEIS A000002)
where the values are 1 or 2 and the run lengths of 1s or 2s are given by the sequence values themselves.
|-| |--| |--| |-||-| |--|
1, 2, 2, 1, 1, 2, 1, 2, 2, ... values
run length 1 2 2 1 1 2 ... lengths are values again
FUNCTIONS
See "FUNCTIONS" in Math::NumSeq for behaviour common to all sequence classes.
FORMULAS
There's no need to keep the entire sequence, nor even the portion between where i is up to and the values past that which those up to i induce. Instead the value at i is determined by the earlier value, which is determined a yet earlier value, etc. At each level only a value and pending count need to be kept. The levels required end up being about log base 1.6 of the position i.
SEE ALSO
Math::NumSeq, Math::NumSeq::GolombSequence
HOME PAGE
http://user42.tuxfamily.org/math-numseq/index.html
LICENSE
Copyright 2011, 2012, 2013, 2014, 2016, 2019, 2020, 2021 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/>.