Not a very mathematically significant sequence, but can you express it algebraically with a single formula?

Consider #omega = -1/2+i sqrt(3)/2#

This has the property that #omega^3 = 1#

Then we can write:

#a_0 = 1#

#a_(i+1) = ((omega^i - omega)(omega^i - omega^2))/((1-omega)(1-omega^2))2a_i+((omega^i-omega^2)(omega^i-1))/((omega-omega^2)(omega-1))(a_i+2)+((omega^i-1)(omega^i-omega))/((omega^2-1)(omega^2-omega))(a_i-1)#

This can be simplified, but it helps to have it in this formulation so you can understand how it works.

When #i = 0# modulo #3#, then:

#((omega^i - omega)(omega^i - omega^2))/((1-omega)(1-omega^2)) = ((1 - omega)(1 - omega^2))/((1-omega)(1-omega^2)) = 1#

#((omega^i-omega^2)(omega^i-1))/((omega-omega^2)(omega-1)) = ((1-omega^2)(1-1))/((1-omega^2)(omega-1)) = 0#

#((omega^i-1)(omega^i-omega))/((omega^2-1)(omega^2-omega)) = ((1-1)(1-omega))/((omega^2-1)(omega^2-omega)) =0#

When #i = 1# modulo #3#, then these coefficient expressions evaluate as #0#, #1# and #0#.

When #i=2# modulo #3#, then these coefficient expressions evaluate as #0#, #0# and #1#.

So we use these to pick out each of the three rules cyclically.