JavaScript Turing Machine

Posted on 5th February 2009 by Ryan Somma in Geeking Out - Tags:

So I was watching the anime series Ghost in the Shell and I don’t feel productive when I’m just watching anime, and I can’t write words when watching videos, so I decided to do some programming purely for fun.

What I did was write a little demonstration of a Turing Machine. Before there were computers, Alan Turing proved on paper that a machine could perform complex tasks. With a strip of paper divided up into places, the machine may read or write a symbol to its current place, move to another place, or change its state. This way it moves up and down the tape, reading and writing symbols, and, depending on its algorithm (instructions), performs calculations.

A Turing Machine

A Turing Machine

The table below is a JavaScript representation of one such machine. Using five tuples worth of instructions, the machine adjusts the ones and zeros to count upwards in binary. With eight positions on the tape, the machine can count up to 255. You may Start the demonstration, or Step through it. The + and symbols speed up or slow down the execution of steps.

The HTML page is located here. If you’d like to download the code, right click on the link, and select “Save link as…” and then edit the code in notepad to play with it. This code could certainly be written more elegantly, but Ghost in the Shell was pretty engaging, and the more basic code more appropriately speaks to the basic mechanics of what this demonstration is supposed to demonstrate.

If you don’t feel like rewriting JavaScript code, you can check out a programmable Java Turing Machine here, with instructions on its very simple programming language here.


  1. This is very cool! Good work. Now, I challenge you to make a non-deterministic JavaScript Turing machine. :)

    Comment by Dave — February 5, 2009 @ 4:27 pm

  2. You had to go there. I spent half an hour yesterday daydreaming about how I could do that, with branching processes using object inheritance to handle the various states… I think for now, I’ll just cop out and say that the set of Non-Deterministic JavaScript Turing Machines includes the the set of Deterministic JavaScript Turning Machines, and pretend that means I’ve created one all ready. : )

    Comment by ideonexus — February 8, 2009 @ 10:04 am

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.