Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Brainfuck Interpreter (Lua) [reposted]
-- Author: Ice Scripter -- This was nice Ice Scripter!! -- Reposted by 'JAMES COLLINS' --[[ Notes: THESE POINTERS ARE NOT OPTIMIZED BUT I DON'T CARE ENOUGH TO OPTIMIZE THEM. All because lua likes to start stuff at 1. It's 5 am at night, and I gotta sleep. ]] local code = "++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++." -- Put code here local pos = 0 local pointer = 1 local loopPos = {} local memorySlots = 8 local memory = {} local output = "" for i = 0, memorySlots -1 do -- Initialize memory slots table.insert(memory, 0) end repeat pos = pos + 1 local current = string.sub(code, pos, pos) if current == "+" then memory[pointer] = (memory[pointer] + 1)%256 elseif current == "-" then memory[pointer] = (memory[pointer] - 1)%256 elseif current == ">" then pointer = (pointer + 1 > memorySlots) and 1 or pointer + 1 elseif current == "<" then pointer = (pointer - 1 < 1) and memorySlots or pointer - 1 elseif current == "." then output = output .. string.char(memory[pointer]) elseif current == "[" then table.insert(loopPos, pos) elseif current == "]" then if memory[pointer] == 0 then table.remove(loopPos, #loopPos) else pos = loopPos[#loopPos] end end until pos >= #code print("\nOutput: " .. output) -- Print memory print("\nMemory: ") for i = 0, memorySlots -1 do print(memory[i+1], i) end
run
|
edit
|
history
|
help
1
kraft1c
CC: LDInterface
multiline string
ok
ok
Conta valores acima da média - LUA
Percentage Calculator (Subscribe to Madflag19)
Testingassets
quick sort
bf-asm compiler test 2