SearchA-ZT › Turing machine simulator

Turing machine simulator

2026 Open source · Public domain Online

An authored, dependency-free Turing machine that runs in the browser. It shows the tape, the read/write head, the current state and step count, and the full transition table on a single canvas. It loads the 3-state busy-beaver champion by default, which runs on its own and halts after 14 steps; the on-screen panel switches to the 4-state busy beaver or a binary-increment machine.

Because the whole machine is plain JavaScript, it plugs into the shared debugger: single-step one transition at a time, edit the configuration, read the tape and transition table as memory, set a breakpoint on entering a state, or watch a tape index.

Runs on: Web browser

Turing machine simulator Online Emulator

Play Turing machine simulator using JavaScript directly in your browser.

Configurations

ConfigurationEmulatorMachineOSLegal
3-state Busy BeaverTuring machine simulatorTuring machineopenOpen ⛶
4-state Busy BeaverTuring machine simulatorTuring machineopenOpen ⛶
Binary incrementTuring machine simulatorTuring machineopenOpen ⛶

Machines emulated

Chips

Notes

Embedding

The whole machine is one authored file, turing.js - no runtime dependency. Drop a <canvas id="screen"> on the page and load the script; it builds the machine, owns its own loop, renders to the canvas, and publishes window.EMU_BOOT. Pick the preset with a global before the script runs:

window.TURING_PRESET = 'bb3';   // 'bb3' | 'bb4' | 'inc'
// <canvas id="screen" width="700" height="520"></canvas>
// <script src="turing.js"></script>

The machine is plain objects. Everything the debugger needs is a live global on EMU_BOOT.core:

MemberKindWhat it does
core.stepOnce()methodExecute exactly one transition (the single-step primitive). Returns false once halted.
core.state / core.head / core.stepsfieldsLive configuration: current state index (−1 = halted), signed head position, transition count.
core.symAt(i) / core.writeTape(i, v)methodsRead / write the (sparse, infinite) tape at index i.
core.table[state][symbol]fieldThe transition rule { w, mv, next } - write symbol, move (±1), next state (−1 = halt).
core.progByte(a)methodThe table as bytes: 4 per rule [write, move, next, 0], rule = state·2 + symbol.
core.load(key) / core.reset()methodsSwitch preset machine / rewind the current one to its start configuration.

Debugger integration

Because the machine is ordinary JavaScript, the shared debugger drives it directly through EMU_BOOT.transport. A Turing machine has no program counter or CPU registers, so the plug-in maps the debugger’s concepts onto the machine’s own:

  • Registers are the configuration: STATE, HEAD, STEP and the symbol under the head SYM, plus a HALT flag. Each is editable, poke HEAD and the tape view re-centres.
  • Memory chips. The Tape is a hex/bits view (one byte per cell; address − 256 is the tape index). The Transition table is the program, shown in the disassembly view via the turing decoder as readable rules like A,0 → 1,R,B.
  • Step runs one transition. Breakpoints break when the machine enters a given state (click any of that state’s rows in the table). Watchpoints break when the head reaches a given tape index.

Manual stepping ignores breakpoints and watchpoints, so you can always step past a break. The run loop checks them after every transition.

Architecture

A Turing machine is the simplest thing that computes: an infinite tape, a head, a finite state, and a table of rules. This simulator keeps each piece as a plain object:

  • core.tape - a sparse map from (possibly negative) integer index to symbol; blanks read as 0, so the tape is effectively infinite in both directions.
  • core.table - the finite control: table[state][symbol] gives the rule to apply. All bundled machines use two symbols {0, 1}, which lets the table be exposed as a flat 4-bytes-per-rule chip.
  • core.stepOnce() - read the symbol under the head, look up the rule, write, move the head one cell, and switch state (or halt). One call is one step.
  • The renderer draws the windowed tape (cells around the head, head highlighted), the current state, the step count and the whole transition table, with the active rule outlined.

The busy-beaver presets are the classic champions: they provably halt (BB-3 after 14 steps writing six 1s; BB-4 after 107 steps writing thirteen), so the default page runs to a visible, finished tape. The step count is capped so any machine terminates.