|
Post by Josh on May 13, 2017 11:13:36 GMT
Brainf*** Interpreter
In this puzzle, you must write a Brainf*** interpreter. If you don't know how the language works, you can take a look at a learnXinYminutes article here. Please note that due to the language name, the web page contains inappropriate language.
You can present this in any way, as long as a user can enter the code that needs to interpreted and your program deals with this correctly. There is a total of 8 commands. If you would like to exclude some commands in your program, you may do so but you must tell us what commands you have excluded.
Make sure that you tell us the language that you completed this in along with the amount of characters it took to write your program if you have golfed your solution.
Good luck!
|
|
chimmihc
New Member
Veteran
Posts: 8
ROBLOX Username: chimmihc
|
Post by chimmihc on May 13, 2017 18:27:12 GMT
|
|
|
Post by Josh on May 13, 2017 19:48:08 GMT
|
|
|
Post by 128Gigabytes on May 14, 2017 2:08:49 GMT
|
|
|
Post by Josh on May 14, 2017 9:55:11 GMT
|
|
|
Post by 128Gigabytes on May 15, 2017 9:39:25 GMT
return (function(source)
return (loadstring("local cells = {[0] = 0; [\"cell\"] = 0;}" .. source:gsub("[^><%+%-%.,%[%]]", ''):gsub("%.", "z"):gsub("%]", "end;"):gsub("%[", "while (cells[cells.cell] ~= 0) do "):gsub("+", "cells[cells.cell] = ((cells[cells.cell] == 255) and 0 or (cells[cells.cell] + 1));"):gsub("-", "cells[cells.cell] = ((cells[cells.cell] == 0) and 255 or (cells[cells.cell] - 1));"):gsub("<", "cells.cell = ((cells.cell == 0) and 30000 or (cells.cell - 1)) if (cells[cells.cell] == nil) then cells[cells.cell] = 0; end;"):gsub(">", "cells.cell = ((cells.cell == 30000) and 0 or (cells.cell + 1)) if (cells[cells.cell] == nil) then cells[cells.cell] = 0; end;"):gsub("z", "io.write(string.char(cells[cells.cell]));"):gsub(",", "cells[\"input\"] = io.read(); cells[\"input\"] = ((cells.input == '') and string.char(13) or cells.input) cells[cells.cell] = string.byte(cells.input:sub(1, 1)) cells[\"input\"] = nil;"))());
end);
|
|