esolang

Struffoli

The pointer steps back two, forward one, back one. The program has to be written in that order.

Zero player rodent · Turing complete: unknown · ●●○ moderate · esolangs.org

Tested with 2 known programs · Test method

Run it

Expected: Hello

The idea

Zero player rodent made Struffoli. The pointer starts one cell past the right end of the program and repeats one pattern. It steps back 2 cells and runs that one, steps forward 1 and runs that one, then steps back 1. So the program runs two cells at a time, from the right end to the left. The specification suggests writing a program normally, then reversing it and rearranging it; swapping each pair, counted from the right end, does that.

Read the story

There is one accumulator and one stack. Numbers are built in the accumulator by counting and doubling, then added to the top of the stack.

The machine

CellDoes
0 ! @Add 1 to the accumulator; set it to 0; double it
1 2 #Push 0; add the accumulator to the top; double the top
9 4 8Duplicate; pop; pop a random number of times, at most the accumulator
6Push one byte of input
3 &Print the top as a character; as a number
5 7Move the pointer forward; back, by the accumulator
$ %Move back 2 if the top equals the accumulator; if it does not
^End the run

After 5 the cell it lands on runs at once, unless it holds 0 to 4, $ or %. After $ and % it runs at once unless it holds $ or %.

Example

Read from the right two at a time, Hello begins 00 @0 @2 22 #2.

Read from the right two at a time, Hello begins 00 @0 @2 22 #2. The accumulator counts to 10, three 2s add it to the top three times, # doubles that to 60 and one more 2 gives 70. Then !00 sets the accumulator to 2, 2 makes 72 and 3 prints H.

Expected: 0
Expected: cat

The truth machine starts with $^. The top of the stack and the accumulator are both 0, so $ jumps back and the ^ is skipped. The next 16 cells count the accumulator up to 49, the code of 1. On 0, % jumps, 0 is printed and 5 throws the pointer 52 cells forward, past the end. It walks back over empty cells to the $^, and this time ^ ends the run. On 1, 5 jumps 3 cells and the program prints 1 forever.

Patterns it teaches

Further

Stack-based

Write your own in Run Convert a program from Struffoli

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run struffoli -e '539003!06%00000000@0@@@000$^' --input '0'
shib manual struffoli

Source

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

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

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