function solve(xs)
localdone, i, length
done = false
i = 2
--print(done)
repeat
if (#xs % i == 0) then
length = math.floor(#xs / i)
--print('len=' .. length)
local j = 1
localcontinue = truewhile (j <= length and continue) dofor k = 1, i - 1 do
--print(xs[j] .. ',' .. xs[j + k * length])
if (xs[j] ~= xs[j + k * length])
thencontinue = false;
--print('con=')
--print(continue)
break;
end
end
j = j + 1
--print('length=' .. length .. " j=" .. j)
end
if (continue) thendone = true end
end
i = i + 1
--print(done)
until done or i >= #xsif (done) then
res = 'res=' .. length
return res
elsereturn 0 end
end
print(solve({1,2,1,2}))
print(solve({1,2,1,1,2,1}))
print(solve({1,2,1,1,1,2,1,0}))