Length
Length is an esoteric programming language created by user:Nailuj29. Its instructions are the length of the lines, so you can hide a Length program in any other program.
Instruction Set
Line Length | Name | Description |
---|---|---|
9 | inp | Pushes the ascii value of the first byte of stdin to the stack. |
10 | add | Pops the top two values from the stack and pushes their sum onto the stack. |
11 | sub | Pops value A from the stack and then value B . Pushes value B - A onto the stack.
|
12 | dup | Duplicates the top value of the stack. |
13 | cond | Pops the top value from the stack. If it is 0, skip the next instruction. If the instruction to be skipped is gotou or push , skip that instructions argument as well.
|
14 | gotou | Sets the program counter to the value of the line under the instruction, skipping that line. |
15 | outn | Pops the top of the stack and outputs it as a number. |
16 | outa | Pops the top of the stack and outputs its ascii value. |
17 | rol | Rotates the stack to the left: [ 7 6 5 ] -> [ 6 5 7 ]
|
18 | swap | Swaps the top two values of the stack: [ 7 6 5 ] -> [ 6 7 5 ]
|
20 | mul | Pops the top two values from the stack and pushes their product onto the stack. |
21 | div | Pops value A from the stack and then value B . Pushes value B / A onto the stack.
|
23 | pop | Pops the top value of the stack |
24 | gotos | Pops the top of the stack and sets the program counter to it (indexed starting at 1). |
25 | push | Pushes the value of the line under this instruction to the stack, skipping that line. |
27 | ror | Rotates the stack to the right: [ 7 6 5 ] -> [ 5 7 6 ]
|
Examples
Hello world
1234567890123456789012345 123456 1234567890123456789012345 123456 1234567890 1234567890123456789012345 123456 12345678901234567890 123456789012 1234567890123456 1234567890123456789012345 123456 1234567890123456789012345 12345 12345678901234567890 1234567890 1234567890123456789012345 1 12345678901 123456789012 1234567890123456 1234567890123456789012345 1234567 1234567890 123456789012 1234567890123456 123456789012 1234567890123456 1234567890123456789012345 123 1234567890 123456789012 1234567890123456 1234567890123456789012345 12345678901 1234567890123456789012345 1234 12345678901234567890 123456789012 1234567890123456 1234567890123456789012345 123456789012 12345678901 1234567890123456 123456789012 1234567890123456789012345 12345678 1234567890 1234567890123456 123456789012 1234567890123456 1234567890123456789012345 123 1234567890 123456789012 1234567890123456 1234567890123456789012345 123456 12345678901 123456789012 1234567890123456 1234567890123456789012345 12345678 12345678901 1234567890123456 1234567890123456789012345 123 1234567890123456789012345 12345678901 12345678901234567890 1234567890123456
Here's a version which is 42 characters shorter. It uses the lyrics of All Star by Smash Mouth
Truth-machine
123456789 1234567890123456789012345 123456 1234567890123456789012345 12345678 12345678901234567890 12345678901 1234567890123 12345678901234 123456789012345 1234567890123456789012345 123456789012345 12345678901234 123456789012354678901234567890 1234567890123456789012345 1 123456789012345 12345678901234 123456789012345
Computational class
Length is Turing complete since it can interpret brainfuck. The interpreter is being created by User:ChuckEsoteric08 but isn't finished yet.
A simpler reduction is from tag.
Using a convenience dialect with jump labels, each production of a 2-tag system in the form s → ab...
translates to
dup push ''s'' sub cond gotou after pop pop push ''a'' rol push ''b'' rol ... gotou start after:
The dup push sub cond
portion duplicates the TOS (which is the first symbol of the word) then subtracts it with the constant symbol we are checking, if they are equal then the cond will run on 0, which will skip the goto command. If they are not equal then the goto will execute. The goto skips ahead of the production.
All productions are converted into this form, concatenated together, with a header at the start which has a series of push instructions which initialize the word, and a final start label. Halt symbols are not given production rules.
Since this dialect is trivial to translate back into Length, the language is Turing complete.