';#+'
Counting is done with a delta that is either plus one or minus one, and - flips it.
Conor O'Brien · Turing complete: unknown · ●●○ moderate
Tested with 5 known programs · Hello World on Try It Online: identical · Test method
Run it
The idea
Conor O'Brien made ;#+ as a bigger sibling of ;#, where ; adds one and # prints. ; adds the delta instead, and the delta can be flipped to minus one. A second accumulator and the + command make numbers grow faster: + adds the other accumulator, times the delta.
Read the story
A Hello World is mostly ;, + and ~, building each letter out of the one before it.
The machine
Two 32-bit accumulators, A and B, a delta of 1 or -1, and 1000 memory cells with a pointer.
| Code | Does |
|---|---|
; | A plus the delta |
: | Pointer plus the delta |
- | Flip the delta |
+ | A plus B times the delta |
~ | Swap A and B |
< > | Load the cell into A, store A in the cell |
. | Move the pointer to cell A |
# | Print A modulo 127 as a character, then set A to 0 |
p | Print A as a number |
* | Read a byte into A, -1 at the end |
( ) | Skip past ) if A is 0; go back to ( if A is not 0 |
! | 1 if A is 0, else 0 |
@ | End the program |
Every other character is ignored. This implementation follows the C interpreter at github.com/ConorOBrien-Foxx/shp, which TIO runs.
Example
The first puts 5 in B and adds it 13 times, 65, an A.
The first puts 5 in B and adds it 13 times, 65, an A. The second counts down from 3: each pass prints, flips the delta to take one off, and flips it back. The third reads 33 and 35 and adds them; @ ends it before the second p.
Patterns it teaches
- Turing tarpit: two registers, a few cells and one loop.
- Encoding tricks: every letter is reached by adding the other accumulator a few times.
Further
See also
Also in Turing tarpits
Write your own in Run Convert a program from ';#+'
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: shp.
Command line
shib run shp -e '*p*p*p' --input 'hi'shib manual shpSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/shp.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language