Jump to content

Thue-Morse: Difference between revisions

Added Lua version
m (→‎{{header|C}}: no point in malloc'ing a fixed length for local use)
(Added Lua version)
Line 152:
}</lang>
<pre>0110100110010110100101100110100110010110011010010110100110010110</pre>
 
=={{header|Lua}}==
<lang Lua>ThueMorse = {sequence = "0"}
 
function ThueMorse:show ()
print(self.sequence)
end
 
function ThueMorse:addBlock ()
local newBlock = ""
for bit = 1, self.sequence:len() do
if self.sequence:sub(bit, bit) == "1" then
newBlock = newBlock .. "0"
else
newBlock = newBlock .. "1"
end
end
self.sequence = self.sequence .. newBlock
end
 
for i = 1, 5 do
ThueMorse:show()
ThueMorse:addBlock()
end</lang>
{{out}}
<pre>0
01
0110
01101001
0110100110010110</pre>
 
=={{header|OASYS Assembler}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.