npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

grumle-turing

v1.0.3

Published

The Turing Machine behind Grumle

Downloads

14

Readme

Turing Machine

Build Status npm

Introduction

The Turing Machine is a computational model first presented by Alan Turing in his 1936 paper on Computability. It is an incredibly simple model. The machine consists of an infinitely long tape and a tape head. The tape consists of boxes known as squares. Each square contains a symbol which is either B (representing a BLANK square) or 1 (representing a square with content and that content being the natural number "1"). The tape head can move along the tape. That is, it can move left or right. The square currently being scanned by the tape head is known as the scanned square, and the symbol of the scanned square is referred to as the scanned symbol. The machine can also print a new symbol into a scanned square.

With that being said, it is important to note that there are only three operations in a Turing Machine: Move Left, Move Right, and Print.

Once the input is loaded into the Turing Machine, its tape is configured to represent such. For instance, given a function f of two inputs x1 and x2, f(3,2) would yield the following initial tape configuration: B 1 1 1 B 1 1 B. To the left of the leftmost B, there are infinitely many Bs. The same applies to the right of the rightmost B. The inputs are represented in a sequence of 1s. For instance, 3 = 1 1 1 and 2 = 1 1. All inputs are separated by a blank square.

The behavior of the machine is dependent on the quadruples provided. A quadruple is a collection of four items in the format: Q1 S A Q2 where Q1 is the machine's current state, S is the scanned symbol, A is the action to perform, and Q2 is the machine's next state once the quadruple is executed. For example, 1 B R 2 is a valid quadruple. It is read as, "Whilst in state one reading a blank, move right and switch to state two." A finite sequence of quadruples concoct a program in a Turing Machine. Furthermore, two or more quadruples cannot have the same first two values. For instance, 4 B R 5 and 4 B L 6 are two invalid quadruples because the machine would not know which quadruple to execute when in state four reading a blank. However, 3 1 R 3 and 3 B L 4 are valid quadruples for the simple reason being that one executes when in state three reading a one and the other when reading a blank.

Note: A square cannot be blank and one, simultaneously.

Lastly, the machine runs as long as it can find a quadruple to execute. For example, if the machine is in state three reading a blank and it finds a quadruple that begins with 3 B, it will execute that quadruple. However, if it cannot find such a quadruple, the machine will halt. A correctly constructed Turing Machine will always halt with the tape head scanning the leftmost B in the tape. To the right of the tape head will be the sequence of ones representing the output. For instance, given a function g(x1, x2) = x1 + x2, g(3,2) = 5 and the final tape configuration will be B 1 1 1 1 1 B. As previously stated, there are infinitely many Bs to the left and right of the leftmost and rightmost Bs, respectively.

Disclaimer: This is just a brief summary of Turing Machines with respect to functions. There is a lot more one could learn about this model, and I highly recommend doing so, independently.

Usage

Install via NPM

npm install grumle-turing --save
import { TuringMachine, Quadruple, Result } from 'grumle-turing';

// Create the quadruples
const quadruples: Quadruple[] = [];
quadruples.push(new Quadruple(1, 'B', 'R', 2));
quadruples.push(new Quadruple(2, '1', 'R', 2));
// etc...

// Expects an array of inputs
const inputs: number[] = [3, 2];

// Instantiate the Turing Machine
const turing: TuringMachine = new TuringMachine(quadruples, inputs);

// Use step() to walk through the execution
const result: Result = turing.step();

/* OR */

// Use start() to execute the entire program
const result: Result = turing.start();

// Access the machine's output in decimal format
// (Only accessible once the entire machine has halted)
console.log(result.output);

// Access the tape's configuration after every step()
// or once the machine halts
console.log(result.tape);

// Access the machine's current state after every step()
// or once the machine halts
console.log(result.state);

Contribute

Once you've forked and cloned the repository, and have created your own development branch, install the dependencies.

npm install

Compile the code using the build script.

npm run build

Testing

It is highly encouraged to write unit tests to ensure the functionality of your changes. Jest is the testing framework used in this project. Store all of your test suites in the tests folder. Run your tests using the test script.

npm run test

Also, it is imperative that any changes made do not break the existing code. Consequently, all pull requests must pass Travis CI/CD tests.

Developer:
Treasure Muchenagumbo

License:
MIT

Version:
1.0.3