Question: how to guess 1 or 2 when rsolve is wrong at some numbers

second has rsolve solution

compare original sequence

accsum(ListTools[Reverse]([seq(patterngroup[k], k=(mm)..(mm+lengthofsequence))])),

with rsolve solution , it start from third number wrong, some number are wrong but correct at next number, 

but i just want to guess next number is 1 or 2

[seq(subs(k=kk, sol), kk=0..(lengthofsequence+1))],

with(SumTools):
with(gfun):
accsum := proc(xx)
local result,mm:
result := []:
for mm from 1 to nops(xx) do
temp := Summation(xx[k], k = 1 .. mm):
result := [op(result), temp]:
od:
return result:
end proc:


patterngroup := [2, 1, 1, 1, 2, 2, 1, 1, 2, 2, 2, 1]: # left is latest, 2,1,1..
lengthofsequence := 5:
for mm from 1 to 12 do
if guessgf(accsum(Reverse([seq(patterngroup[k], k=(mm)..(mm+lengthofsequence))])), x) = FAIL then
print(patterngroup[mm]):
else
sol := rsolve(listtorec(accsum(ListTools[Reverse]([seq(patterngroup[k], k=(mm)..(mm+lengthofsequence))])), u(n))[1], u(k)):
acxxc := accsum(ListTools[Reverse]([seq(patterngroup[k], k=(mm)..(mm+lengthofsequence))])):
olist := [seq(patterngroup[k], k=(mm)..(mm+5))]:
#start from 0
print(patterngroup[mm], olist, accsum(ListTools[Reverse]([seq(patterngroup[k], k=(mm)..(mm+lengthofsequence))])), [seq(subs(k=kk, sol), kk=0..(lengthofsequence+1))], sol, subs(k=(lengthofsequence+1), sol), subs(k=(lengthofsequence+1), sol)-acxxc[nops(acxxc)]):
end if:
od:
 

Please Wait...