Snake Shit
A snake crawls over the program. The only number it has is the length of its tail.
2022 · Turing complete: unknown · ●●○ moderate · esolangs.org
Tested with 4 known programs · Test method
Run it
The idea
Snake Shit dates from 2022. The program is a grid, and a snake moves over it one cell at a time, running whatever command its head lands on. The snake holds one number, the length of its tail. Lengths can be saved under one-character names and loaded back, which is enough for loops, counters and a number guessing game. When the snake moves onto a cell with no character, the program ends.
The machine
| Command | Does |
|---|---|
$> | Start here, moving the way the arrow points |
^ > v < | Turn |
+n -n =n | Add to, take from or set the length |
?n | Set the length to a random number below n |
@c %c | Save the length under the name c; load it |
& * | Read a number into the length; print the length |
#c | Print the character c |
~x | Run the command x if the length is not 0 |
Arguments always sit to the right of their command, whichever way the snake comes in. The specification does not say what happens when the snake runs over an argument. Its examples need two rules. An argument belongs to its command, so the snake passes it by. And ~ runs its command by stepping onto it, so ~v turns down one column to the right of the ~.
Example
The Hello World.
The Hello World. The snake prints the character after each # and leaves the grid after the last one.
The truth machine reads a number into the length. On 0 the ~ does nothing, the snake passes over the v and prints 0 at the end of the row. On 1 it turns down into a square loop that prints 1 for ever.
Test x10 sets the length to 10 and goes round a loop that prints test, taking 1 off each time. When the length is 0 the ~ no longer turns it, and the snake climbs the left column to the top.
The specification says the end is a line with lol, but the column also holds #!.
Patterns it teaches
- Two-dimensional control flow, with one number for all the memory.
Further
See also
Two-dimensional languages
Write your own in Run Convert a program from Snake Shit
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: snake-shit.
Command line
shib run snake-shit -e '$>#H#e#l#l#o# #W#o#r#l#d#!#\n'shib manual snake-shitSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/snake-shit.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org