a(1) = 1; for n>1, a(n) = largest integer k such that the word a(1)a(2)...a(n-1) is of the form XY^k for words X and Y (where Y has positive length), i.e. the maximal number of repeating blocks at the end of the sequence so far.

1, 1, 2, 1, 1, 2, 2, 2, 3, 1, 1, 2, 1, 1, 2, 2, 2, 3, 2, 1, 1, 2, 1, 1, 2, 2, 2, 3, 1, 1, 2, 1, 1, 2, 2, 2, 3, 2, 2, 2, 3, 2, 2, 2, 3, 3, 2, 1, 1, 2, 1, 1, 2, 2, 2, 3, 1, 1, 2, 1, 1, 2, 2, 2, 3, 2, 1, 1, 2, 1, 1, 2, 2, 2, 3, 1, 1, 2, 1, 1, 2, 2, 2, 3, 2, 2, 2, 3, 2, 2, 2, 3, 3, 2, 2, 2, 3, 2, 1, ...

The numbers in first 24.000 elements serve as a check for the correctness of a solution. They can be inspected here rb090822.csv as well.

For a thorough study on this sequence, cf. A Slow-Growing Sequence Defined by an Unusual Recurrence

## Calculation as in OEIS

No such calculations is provided until now.

## Collected definitions

The first solution was from Ambrus

```   gi1=: , [:>:[:>./ -@:>:@:i.@:<.@:-:@:# (0 i.~2-:/\])@(]\) |.
gij=: 3 :'gi1^:(y-2) 1 1'```

A slight improvement came from Boss1

```   gi2=: ,~ [:>:[:>./ -@:>:@:i.@:<.@:-:@:# (0 i.~2-:/\])@(]\) ]
gij2=: 3 :'|. gi2^:(y-2) 1 1'```

Further (performance) improvement was in Boss2

```iofifh=: {. I. at e.~ >:@>.@:-:@:# {. ]         NB. index of first in first halve
fiwd=: 0 i.~ 2 -:/\ ]           NB. first index where different
oie=: 1:`]@.(0 < #)     NB. one if empty
gwr1=: 3 : '|.(,~ [:>: [:>./ -@([: oie [: }. iofifh) fiwd@(]\) ])^:(y-2) 1 1'

dio=: (,~@[)`(,~)@.(1~:])       NB. double if one
gwr2=: 3 : 'y {. |.(] dio [:>: [:>./ -@([: oie [:}. iofifh) fiwd@(]\) ])^:(y>#)^:(y-2) 1 1 '```

Finally the scene was set by Boss3

```iofifh=: {. I.@e.~ >:@>.@:-:@:# {. ]
fiwd=: 0 i.~ 2 -:/\ ]
oie=: 1:`]@.(0 < #)

scn2=: 3 : 0
z=. <2
le=. 1
for. i. y-1 do.
t=. < ({.~ le -~ #) }. ([: (,~ [:>: [:>./ -@([: oie [: }. iofifh)
fiwd@(]\)])^:(1 ~: {.)^:(_) 2,]) ;z
le=. # ; z=. t ,z
end.
|. |.&.> z
)

gwr3=: 3 : 0
le=. <:<.2^.y
t=. scn2 le
z=. 1
for_s. t do. z=. (;s) ,~ z , z end.
if. y>#z do. z, (y-#z) {. z else. y {. z end.
)```

## Correctness

A first check on correctness is that "a 4 appears for the first time at position 220".

```   4 i.~ gij 250
219
4 i.~ gij2 250
219
4 i.~ gwr1 250
219
4 i.~ gwr2 250
219
4 i.~ gwr3 250
219
2 -:/\(gij 500);(gij2 500);(gwr1 500);(gwr2 500);gwr3 500
1 1 1 1```

A further check can be made by inspecting where 4's occur.

```   4 (I.@e.~)gwr3 5000
219 439 660 880 1104 1324 1545 1765 1990 2210 2431 2651 2875 3095 3316 3536 3770 3990 4211 4431 4655 4875```

## Comparing performances

RE Boss/OEIS/A090822 (last edited 2010-12-08 18:27:01 by RE Boss)