Mukha
One counter, one stack, one line of code, and a pointer that walks it to the right and back.
ChuckEsoteric08 · Turing complete: unknown · ●●○ moderate · esolangs.org
Tested with 2 known programs · Test method
Run it
The idea
ChuckEsoteric08 made Mukha. Its program is a single line, but the pointer can turn around on it, so the same commands run once going right and again coming back. Two of them only work in one direction. \ skips the next command when the pointer moves left and / when it moves right. Loops are made with a stack of positions, pushed by ( and jumped back to by ).
Read the story
Mukha has no input and no output. Its specification describes every example by what it leaves in the accumulator, so this implementation prints the accumulator when the program ends.
The machine
An accumulator that starts at 0, a stack of positions, and a pointer that starts on the first character moving right.
| Char | Does |
|---|---|
+ | Add 1 to the accumulator |
- | Take 1; skip the next command if the result is below 0 |
( ) | Push this position; pop one and go back there |
; | Pop; skip the next command if the stack was empty |
: | Go back to the first character |
> < | Move right or left from now on |
\ / | Skip the next command when moving left, or right |
The program ends when the pointer leaves the line at either end.
Example
The loop from the specification.
The loop from the specification. It counts to 3, pushes the position of (, and takes 1. Each ) jumps back to (, which pushes its position again, until - goes below 0 and skips the ).
The walk from the specification. Going right, each / skips a -, so the accumulator reaches 3. The < turns the pointer around, and on the way back each \ skips a +, so it falls to 0 before the pointer leaves on the left.
The third program in the specification, >+<, bounces between both ends and adds 1 forever.
Patterns it teaches
- Counter machines: one counter that can add, take away and test for below zero, with jumps kept on a stack.
Further
See also
Stack-based
Write your own in Run Convert a program from Mukha
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: mukha.
Command line
shib run mukha -e '+++(-)'shib manual mukhaSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/mukha.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org