++ed by:
Kevin Ryde
and 1 contributors

# NAME

Math::NumSeq::ReReplace -- sequence of repeated replacements

# SYNOPSIS

`````` use Math::NumSeq::ReReplace;
my \$seq = Math::NumSeq::ReReplace->new;
my (\$i, \$value) = \$seq->next;``````

# DESCRIPTION

This is a sequence by David Madore formed by repeatedly replacing every N'th occurrence of a term with N.

``    1, 2, 1, 2, 3, 3, 1, 2, 4, 4, 3, 4, ...``

## Stages

The optional `stage => \$n` parameter limits the replacements to a given number of stages of the algorithm. The default -1 means unlimited.

The generating procedure begins with all 1s,

``    stage 0: 1,1,1,1,1,1,1,1,1,1,1,1,...``

Then every second 1 is changed to 2

``    stage 1: 1,2,1,2,1,2,1,2,1,2,1,2,...``

Then every third 1 is changed to 3, and every third 2 changed to 3 also,

``    stage 2: 1,2,1,2,3,3,1,2,1,2,3,3,...``

Then every fourth 1 becomes 4, fourth 2 becomes 4, fourth 3 becomes 4.

``    stage 3: 1,2,1,2,3,3,1,2,4,4,3,4,...``

The replacement of N at every Nth is applied separately to the 1s, 2s, 3s etc remaining at each stage.

# FUNCTIONS

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

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

Create and return a new sequence object.

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

Return true if `\$value` occurs in the sequence. This merely means integer `\$value >= 1`.