--//This script returns an iterator over the first n copies of the look-and-say sequence
function LookAndSaySequence(n)
print("1")
local t = {1} --//Table
return function()
local ret = {} --//Empty table
for i, v in ipairs(t) do
if t[i-1] and v == t[i-1] then
ret[#ret - 1] = ret[#ret - 1] + 1
else
ret[#ret + 1] = 1
ret[#ret + 1] = v
end
end
t = ret
n = n - 1
if n > 0 then
return table.concat(ret)
end
end
end
for iterator in LookAndSaySequence(10)--[[The number inside lookandsayreq(n) is however many outputs you will get, minus one.]] do
print(iterator)
end
--//I recommend not to put more than 35 in lookandsayseq(n) if you do not have the fastest computer.
Try it out yourself!
~~Nanaluk01