From Esolang
Jump to navigation Jump to search

Sprupine (named after Spruce and Pine trees) is a self-modifying esolang by User:BoundedBeans with binary tree code.


Keep in mind, a binary tree can be represented as an array.

For example:

   / \
  5   9
 / \ / \
6  0 2  3

Can be represented as:

[1, 5, 9, 6, 0, 2, 3]

The code is represented as a list of strings, separated by newlines. The number of code must be Tree-ifiable. In practice, this simply means the number of lines should be 2^n - 1, where n is the number of levels in the tree.

Each line is a string.


The program starts at the root node. At every branch, it checks the currently pointed value. If it is 0, execution travels to to the left branch. If it is not 0, execution travels to the right branch. If it reaches the end of the code on a leaf node, the program halts.


= Ignore all instructions until another = is reached.
+-><., Standard brainfuck instructions, operating on an infinite (in both directions) tape of wrapping cells that can go up to 255. I/O is in UTF-8, to allow unicode characters to be printed.
\ Skip the next instruction if the currently pointed cell is zero
/ Skip the next instruction if the currently pointed cell is non-zero
# Start a hashtag sequence. Takes all of the code until n hashtags later, where n is the number of code strings that would be on the next level after the level with the leaves. Splits it by hashtags and adds children to all of the leaves on the tree, putting the contents between the hashtags into them. If there aren’t enough hashtags, loop around the code to get more hashtags, even the one that started the hashtag sequence. If it wrapped around to get more hashtags, the node will act as if it has finished; otherwise it will continue after the last hashtag in the sequence.
H Toggles a flag. When the flag is on and control transfers to the next string, appends a hashtag to it and toggles the flag again
P Transfers control to the parent node
G Transfers control to the grandparent node
^ Deletes all leaves on the last level
@ Takes the rest of the current node, appends it to both children. The node acts like it has finished.
% Takes the rest of the current node, appends it to the parent.
$ Takes the current node string after this symbol, and appends it to all leaf nodes. The rest of the node is still executed, but a way to get around this is to have the rest of the node in equal signs (making it not run), but having the leaf nodes all already end with an equal sign. It will skip nothing, then skip with no more equal signs, causing it to end normally.
! Toggles a flag. It starts off false. When it is true, the commands @,%,$ prepend instead.
"anything" A comment.




This version takes up only one line.