Counting Peanuts

Named for the comic strip above, the Linus Sequence is defined as follows:

The sequence composed of 1s and 2s obtained by starting with the number 1, and picking subsequent elements to avoid repeating the longest possible substring. The first few terms are 1, 2, 1, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2, 2, …

The sequence’s sister set, the Sally Sequence gives “gives the sequence of lengths of the repetitions which are avoided in the Linus sequence.”

Both sequences are listed in the astounding Online Encyclopedia of Integer Sequences. High five on that one, Internet.