esolang

Parity

A list of numbers that runs itself. Even numbers count up, odd numbers jump.

imcute · Turing complete: unknown · ●●○ moderate · esolangs.org

Tested with 2 known programs · Test method

Run it

Expected: 2 1 2 1 result: 2 1

The idea

imcute named Parity after its two instructions, which an even or an odd number picks. A program is a list of integers, and that list is the whole memory. An even number adds 1 to a number in the list, so a program rewrites itself as it runs. An odd number jumps. There is no conditional jump, and the specification calls its Turing completeness questionable.

Read the story

The specification names two dialects, one whose list starts at place 0 and one whose list starts at place 1. This implementation runs the first, the one the Python runs.

The machine

The pointer starts at place 0. Each step looks at the number p there.

pDoes
EvenAdd 1 to the number at place p / 2 and go on to the next place
OddJump to the place named by the number at place (p - 1) / 2

After every step the whole list is printed. A place outside the list ends the run with result: and the list once more. Like the Python, a run also stops after 1,000 steps, with the message Oops!Code too long to run.If this is intentional,make line one to something supra big.

Example

The 2 adds 1 at place 1 and moves on.

The 2 adds 1 at place 1 and moves on. The 1 there is odd, and jumps to the number at place 0, which is 2 and outside the list.

The count to infinity for the other dialect. The 6 adds 1 at place 3, and the odd 9 looks up place 4, which does not exist.

Expected: 6 9 0 2 result: 6 9 0 2

The count to infinity for this dialect is 4 7 0 0. The 4 adds 1 at place 2, and the 7 jumps to place 0, the number at place 3. It prints 1,000 lists, counting the third number up to 500, and then the Oops message.

Patterns it teaches

Further

Also in Turing tarpits

Write your own in Run Convert a program from Parity

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: parity.

Command line

shib run parity -e '4 7 0 0'
shib manual parity

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/parity.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org