Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
24
Task/Execute-Brain-/Lua/execute-brain-.lua
Normal file
24
Task/Execute-Brain-/Lua/execute-brain-.lua
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
local funs = {
|
||||
['>'] = 'ptr = ptr + 1; ',
|
||||
['<'] = 'ptr = ptr - 1; ',
|
||||
['+'] = 'mem[ptr] = mem[ptr] + 1; ',
|
||||
['-'] = 'mem[ptr] = mem[ptr] - 1; ',
|
||||
['['] = 'while mem[ptr] ~= 0 do ',
|
||||
[']'] = 'end; ',
|
||||
['.'] = 'io.write(string.char(mem[ptr])); ',
|
||||
[','] = 'mem[ptr] = (io.read(1) or "\\0"):byte(); ',
|
||||
}
|
||||
|
||||
local prog = [[
|
||||
local mem = setmetatable({}, { __index = function() return 0 end})
|
||||
local ptr = 1
|
||||
]]
|
||||
|
||||
local source = io.read('*all')
|
||||
|
||||
for p = 1, #source do
|
||||
local snippet = funs[source:sub(p,p)]
|
||||
if snippet then prog = prog .. snippet end
|
||||
end
|
||||
|
||||
load(prog)()
|
||||
Loading…
Add table
Add a link
Reference in a new issue