Kevin Ryde > Math-NumSeq-65 > Math::NumSeq::Kolakoski

Math-NumSeq-65.tar.gz

Dependencies

Annotate this POD

Website

CPAN RT

 Open 0
View/Report Bugs
Module Version: 65   Source   Latest Release: Math-NumSeq-69

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

A sequence 1,2,2,1,1,2,1,etc, each run length being given successively by the sequence itself.

Starting from 1,2, at i=2 the values is 2, so there should be a run of two 2s. Then at i=3 value 2 means two 1s. Then at i=4 value 1 means a run of one 2. The value alternates between 1 and 2 and the sequence values themselves determine the run length to give that value, either 1 or 2.

FUNCTIONS

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

`\$seq = Math::NumSeq::Kolakoski->new ()`

Create and return a new sequence object.

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.

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