Skip to content

Instantly share code, notes, and snippets.

@raganwald
Created March 21, 2017 02:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raganwald/90fbb27f99a038c30eff7685bd0da0e4 to your computer and use it in GitHub Desktop.
Save raganwald/90fbb27f99a038c30eff7685bd0da0e4 to your computer and use it in GitHub Desktop.
The simplest building block for Life
// This two-dimensional Turing Machine starts in the upper-left-hand corner of the
// tableau and counts the number of 1s surrounding a center cell, and
// then determines whether the centre cell should be born, survive, or die.
const life = [
['start', 0, 'ul-zero', Move(RIGHT)],
['start', 1, 'ul-one', Move(RIGHT)],
['ul-zero', 1, 'uc-one', Move(RIGHT)],
['ul-zero', 0, 'uc-zero', Move(RIGHT)],
['uc-zero', 0, 'ur-zero', Move(DOWN)],
['uc-zero', 1, 'ur-one', Move(DOWN)],
['ur-zero', 0, 'mr-zero', Move(DOWN)],
['ur-zero', 1, 'mr-one', Move(DOWN)],
['mr-zero', 0, 'lr-zero', Move(LEFT)],
['mr-zero', 1, 'lr-one', Move(LEFT)],
['lr-zero', 0, 'lc-zero', Move(LEFT)],
['lr-zero', 1, 'lc-one', Move(LEFT)],
['lc-zero', 0, 'll-zero', Move(UP)],
['lc-zero', 1, 'll-one', Move(UP)],
['ll-zero', 0, 'zero', Move(RIGHT)],
['ll-zero', 1, 'one', Move(RIGHT)],
['ul-one', 0, 'uc-one', Move(RIGHT)],
['ul-one', 1, 'uc-two', Move(RIGHT)],
['uc-one', 0, 'ur-one', Move(DOWN)],
['uc-one', 1, 'ur-two', Move(DOWN)],
['ur-one', 0, 'mr-one', Move(DOWN)],
['ur-one', 1, 'mr-two', Move(DOWN)],
['mr-one', 0, 'lr-one', Move(LEFT)],
['mr-one', 1, 'lr-two', Move(LEFT)],
['lr-one', 0, 'lc-one', Move(LEFT)],
['lr-one', 1, 'lc-two', Move(LEFT)],
['lc-one', 0, 'll-one', Move(UP)],
['lc-one', 1, 'll-two', Move(UP)],
['ll-one', 0, 'one', Move(RIGHT)],
['ll-one', 1, 'two', Move(RIGHT)],
['uc-two', 0, 'ur-two', Move(DOWN)],
['uc-two', 1, 'ur-three', Move(DOWN)],
['ur-two', 0, 'mr-two', Move(DOWN)],
['ur-two', 1, 'mr-three', Move(DOWN)],
['mr-two', 0, 'lr-two', Move(LEFT)],
['mr-two', 1, 'lr-three', Move(LEFT)],
['lr-two', 0, 'lc-two', Move(LEFT)],
['lr-two', 1, 'lc-three', Move(LEFT)],
['lc-two', 0, 'll-two', Move(UP)],
['lc-two', 1, 'll-three', Move(UP)],
['ll-two', 0, 'two', Move(RIGHT)],
['ll-two', 1, 'three', Move(RIGHT)],
['ur-three', 0, 'mr-three', Move(DOWN)],
['ur-three', 1, 'too-many', Move(LEFT)], // short circuit
['mr-three', 0, 'lr-three', Move(LEFT)],
['mr-three', 1, 'too-many', Move(LEFT), Move(UP)], // short circuit
['lr-three', 0, 'lc-three', Move(LEFT)],
['lr-three', 1, 'too-many', Move(UP)], // short circuit
['lc-three', 0, 'll-three', Move(UP)],
['lc-three', 1, 'too-many', Move(UP), Move(RIGHT)], // short circuit
['ll-three', 0, 'three', Move(RIGHT)],
['ll-three', 1, 'too-many', Move(RIGHT)],
['zero', 0, HALT, Write(0)],
['zero', 1, HALT, Write(0)],
['one', 0, HALT, Write(0)],
['one', 1, HALT, Write(0)],
['two', 0, HALT, Write(0)],
['two', 1, HALT, Write(1)],
['three', 0, HALT, Write(1)],
['three', 1, HALT, Write(1)],
['too-many', 0, HALT, Write(0)],
['too-many', 1, HALT, Write(0)]
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment