Posts

Showing posts from July, 2014

Brainfuck interpreter in javascript

I got bored today and decided to make a brainfuck interpreter with javascript. After I was done I did a quick google search to see what other people did for a js solution to compare and constrast however I couldn't find anything with less than 100 lines (to be fair others had more features such as step debugging and config options). So here I present my rather naive (but small) version in 17 lines of javascript, 328 bytes manually minified. function bf(code, input){ var src = "var ptr = 0, inptr = 0, output = '', data = new Uint8Array(30000);", op = { '>': '++ptr;', ' ...and some samples... // hello world bf('++++++++[>++++[>++>+++>+++>+ +>+>->>+[ >.>---.+++++++..+++.>>. >+.>++.') // echo input bf(',[.,]', 'input') // echo reverse input bf(',[>,] Here's a link to a live sample.