Posts

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.

Conway's Game of Life as a data uri

A while ago I came across a post on Hacker News that showed a version of the game "snake" that someone had built to work from a data uri . When I initially saw it I became obsessed because I though it was pretty neat (and because there wasn't much code). Fast forward a few months and I came up with the idea to attempt the same sort of thing except with Conway's Game of Life. It's implemented in javascript using the canvas element and requestAnimationFrame (instead of setTimeout or setInterval). Also instead of using a 2d array I've used a 1d array (no lazy dead edges though, it still wraps). Here's the copy and paste version: data:text/html,<script>var r=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame;document.addEventListener('DOMContentLoaded',function(){for(var e,f,b=256,c=256,d=[],g=2,h=null,i=function(a){(!h||a-h>41.7)&&(f.setTransform(1,0,0...