From Esolang
Jump to navigation Jump to search

Rubic is an esoteric programming language created by User:Digital Hunter inspired by the Rubik's Cube puzzle.

Rubic instructions consist of turns of a virtual cube to alter its stored information, and operations performed using these values.


Because Rubik's Cube notation isn't always consistent from one source to another, the notation as used in Rubic is defined here.

Because I'm a fan of case-insensitivity, every instruction in Rubic is case-insensitive (r and R mean the same thing here).

R, U, L, F, B, and D indicate a clockwise quarter turn of the right, top, left, front, back, and bottom faces respectively.

An S, M, or E turn is a rotation of the center slice of the cube parallel and in the same direction as an F, R, or U turn respectively. (Some people do it differently; I am strongly angered at those people).

Putting a single quote after a turn indicates that it is in the anticlockwise direction: R' is an example.

Putting a 2 after a letter indicates a 180° turn.

W, G, O, W', G', and O' indicate the colours white, green, orange, yellow, blue, and red respectively.

Data and arithmetic

There are technically 37 accessible variables for data storage. 36 of these correspond to the state of the cube itself, and the 37th is a lone integer henceforth referred to as The Variable.

The Variable has a default value of zero (0) at initialisation. Operations may be used to interact with The Variable and change its value:

Operation Effect
.x Set The Variable to the value of x.
+x Add the value of x to The Variable.
-x Subtract the value of x from The Variable.
*x Multiply The Variable by the value of x.
/x Divide The Variable by the value of x, floored. Sets The Variable to zero if x is zero.
%x Set The Variable to the remainder that would result from division by x. The Variable is unchanged if x is zero.

However, instead of a numerical value of x, Rubic performs operations using the numbers of stickers on certain sides. (Thus, a gimmick!)

In code, x is replaced by a call for two colours placed side-by-side. For example, a snippet such as wg evaluates to the number of green stickers on the side with the white center piece. For consistency, gg from a solved cube gives 8, demonstrating that the center piece is never counted and is only used for locating the side you wish to reference.

Each one of these 36 colour variables can take on an integer value from 0 to 8, which can just be shown with a few minutes of fiddling around with a Rubik's Cube.

Input and output

Input is implemented in terms of output, which will be explained with a few scrolls down the page.

This leaves us with output. ! will output The Variable (mod 128) as an ASCII character. That's that.


Rubic supports one type of loop, denoted by a sequence of instructions enclosed within parentheses. ( stuff ) will run stuff a number of times determined by the value of The Variable prior to entering the loop.

If The Variable was positive before the loop, say, five (5), then stuff will be run exactly five times.

If The Variable was zero before the loop, stuff will not be run.

Here's the fun part. A negative value in The Variable, say, negative five (-5), will run something five times. The instructions in stuff will be executed in reverse order, and swapped with its opposite. I use specifics here, but replacing any letter with one of the same type will have the same effect.

r r'
r2 r2. Is its own opposite.
.wg Instead of setting The Variable to wg, The Variable is set to the negative of wg.
+oo -oo
*g'o /g'o
%w'o' Cannot be undone. Is ignored.
! Takes a single ASCII character input and sets The Variable to this character.
( stuff ) Is run normally.

Initialisation and syntax

As stated prior, The Variable holds a value of 0 at the start of every program. The virtual cube itself starts in its solved state, with its white (w) face on top (u), its green (g) face facing "you" (f), and its orange (o) face on "your" left (l).

All instructions are separated by spaces (" "). This includes leaving a space before and after every open and close parenthesis.

Example programs

Hello, world!

.ww ( +ww ) ! +ww +ww +ww +ww r -wg ! +oo b -og ! ! +wo' ! b' .wg *oo +oo ! *wg -oo b -og ! b' +oo +oo +oo ! +wg ! l' -wg ! -oo ! .wg *wg r -wg ! .oo +ww !