# NAME

Math::NumSeq::HofstadterFigure -- sequence excludes its own first differences

# SYNOPSIS

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

# DESCRIPTION

This is Douglas Hofstadter's "figure" sequence which comprises all integers except those which are differences between its own successive values,

``    1, 3, 7, 12, 18, 26, 35, 45, 56, 69, 83, 98, ...``

So for example at value=1 the next cannot be 2 because the difference 2-1=1 is already in the sequence, so value=3 with difference 3-1=2 is next. Then the next cannot be 4 since 4-3=1 is already in the sequences, and likewise 5-3=2 and 6-3=3, so the next is value=7 with 7-3=4 not already in the sequence.

The effect is that the sequence increments by 1,2,3,4, etc but excluding values of the sequence itself. This makes it close to the Triangular numbers i*(i+1)/2, but incrementing by a little extra at the places it skips its own values.

## Start Value

The optional `start => \$value` can give the first value for the sequence, instead of the default 1. For example starting at 2

``    2, 3, 7, 12, 18, 26, 35, 45, 56, ...``

or starting at 5

``    5, 6, 8, 11, 15, 22, 31, 41, 53, 66, ...``

The differences are still the values not in the sequence, so for example starting at 5 means the differences are 1, 2, 3, 4 before skipping 5 and 6.

In general the effect is to push the first skip up a bit, but still settles down to grow roughly like the triangular numbers.

The start > must be 1 or more. If the start was 0 then the first value and first difference would always be the same, contradicting the conditions for the sequence.

# FUNCTIONS

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

`\$seq = Math::NumSeq::HofstadterFigure->new ()`
`\$seq = Math::NumSeq::HofstadterFigure->new (start => \$value)`

Create and return a new sequence object.