Struffoli

From Esolang
Jump to navigation Jump to search

Struffoli is an esoteric programming language that was created by User:Zero player rodent. The instruction pointer in Struffoli moves to different instructions in a way that requires code to be arranged in a specific order for it to work properly.

Description

In Struffoli, the instruction pointer starts at the last instruction to the right in the program. The instructions are stored in multiple memory cells. The instruction pointer moves to different instructions in this order:

Move backwards 2 cells, execute instruction.
Move forward 1 cell, execute instruction.
Move backwards 1 cell.

It will repeat that pattern until the program terminates. One way to make programs in Struffoli is to write the program normally, and then reverse it and rearrange the instructions.

Commands

Command Outcome
0 Increment the accumulator.
1 Push 0 onto the stack.
2 Add a value equal to the number stored in the accumulator to the value at the top of the stack.
3 Print the ASCII character associated with the value on the top of the stack
4 Pop the value at the top of the stack off of the stack.
5 Move the instruction pointer forward an amount of times equal to the current value in the accumulator.
6 Push one byte of input onto the stack.
7 Move the instruction pointer backwards an amount of times equal to the current value in the accumulator.
8 Pop the value off of the top of the stack a random amount of times, the highest possible amount of times is equal to the value in the accumulator.
9 Push the value at the top of the stack to the top of the stack. (Duplicate the value at the top of the stack.)
! Set the value that is stored in the accumulator to 0.
@ Add the value in the accumulator to the value of the accumulator. (Multiply the value in the accumulator by 2.)
# Add the value at the top of the stack to the value at the top of the stack. (Multiply the value at the top of the stack by 2.)
$ Make the instruction pointer move backwards 2 times if the value at the top of the stack is equal to the value stored in the accumulator.
% Make the instruction pointer move backwards 2 times if the value at the top of the stack is not equal to the value stored in the accumulator.
^ Terminate the program.
& Print the value at the top of the stack.

Code Examples

Program that prints "Hello".

39200!033020@30022!@@002!@2@0003!02!0#222@2@000

Truth machine.

539003!06%00000000@0@@@000$^

Cat program.

596300

Program that counts infinitely.

5@@002&!0

Program that reverses input. (This program expects a newline at the end of input, and does not terminate.)

5343434343434343434546$0@0@!0

Slot machine game. Keep playing until you match 3 characters.

338380800009!0000!022@2@020222202!129220@0@
222202!10900002!220@0@222222109!22@2@020222
2109!0000!022@2@020222202!129220@0@222202!1


External resources

Interpreter source code (Ruby)