# turing-machine

> A simplistic simulation of turing machines written in TypeScript

Latest version **0.5.5** (published 2017-09-30) · ISC license · 0 weekly downloads

## Install

```sh
npm install turing-machine
pnpm add turing-machine
yarn add turing-machine
bun add turing-machine
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.5.5 |
| Published | 2017-09-30 |
| First published | 2017-09-29 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Pedro M. Silva |
| Maintainers | pedromsilva |
| Keywords | graphs, turing, turing machine, automata |

## Links

- npm: https://www.npmjs.com/package/turing-machine
- npm.io page: https://npm.io/package/turing-machine

## Dependencies (3)

- [mz](https://npm.io/package/mz.md) ^2.7.0
- [itt](https://npm.io/package/itt.md) ^0.2.1
- [chalk](https://npm.io/package/chalk.md) ^2.1.0

## Alternatives

- [d3-force-3d](https://npm.io/package/d3-force-3d.md) — 1.0M weekly downloads
- [ng2-charts](https://npm.io/package/ng2-charts.md) — 486.8K weekly downloads
- [@arcgis/core](https://npm.io/package/@arcgis/core.md) — 257.8K weekly downloads
- [react-sparklines](https://npm.io/package/react-sparklines.md) — 249.3K weekly downloads
- [react-native-gifted-charts](https://npm.io/package/react-native-gifted-charts.md) — 182.3K weekly downloads

## Recent versions

- 0.5.5 (latest) — 2017-09-30
- 0.5.0 — 2017-09-29

## README

# Turing Machine
A simplistic simulation of turing machines written in TypeScript. Tested on NodeJS v8, although eralier versions should word as well.

## Installation
The module is available through npm as:
```shell
npm install --save turing-machine
```

## Usage
We can use pre-built machines.
```typescript
import { EraseMachine } from 'turing-machine/pre-built';

// In this case, the erase machine requires the domain of our language
const eraseMachine = new EraseMachine( [ 'a', 'b' ] );

const eraseTape = Tape.fromString( 'aaabb', 2 );

eraseMachine.diagnose( eraseTape );
```

Or we can create our own custom machines.
```typescript
import { TuringMachine, Tape, TapeMovement } from 'turing-machine';

// Let's create a machine that accepts a's and b's and removes all the a's.
const machine = new TuringMachine();

const stateInitial = machine.addState( '0' );

const stateConsume = machine.addState( '1' );

// We can even compose machines!
const stateErase = machine.addState( '2', new EraseMachine( [ 'a', 'b' ] ) );

const stateRollback = machine.addState( '3' );

const stateFinal = machine.addState( '4' );

// After we have defined the states, we can add transitions between them
stateInitial.addTransition( stateConsume, [ null, null, TapeMovement.Right ] );
stateConsume.addTransition( stateErase, [ 'a', 'a', TapeMovement.Center ] );
stateConsume.addTransition( stateConsume, [ 'b', 'b', TapeMovement.Right ] );
stateConsume.addTransition( stateRollback, [ null, null, TapeMovement.Left ] );
stateErase.addTransition( stateConsume );
stateRollback.addTransition( stateRollback, [ 'b', 'b', TapeMovement.Left ] );
stateRollback.addTransition( stateFinal, [ null, null, TapeMovement.Center ] );

machine.setInitialState( stateInitial );

machine.setFinalState( stateFinal );

// Automatically enables debug mode and prints the productions used and the result
machine.diagnose( 'bbaabab' );
// Otherwise, just call the method run and get the final Tape state
machine.run( 'bbaabab' );

// Additionaly, it's also possible to generate the Dot representation of our graph
machine.toDot();
// Or save it directly to a file
machine.toDotFile( 'graph.dot' );
```

---
_Source: https://npm.io/package/turing-machine · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
