)<@OP
Try it online: once, twice, thrice.
Explanation
Cubix is a stack-based language whose instructions are wrapped around the outside of a cube. Important to note is that the stack is initially filled with infinite zeroes, which allows us to "pull values out of thin air" with operators rather than pushing them explicitly.
I must admit that this was found by a brute-forcer; I never would have found it on my own. In fact, @MartinEnder was the one who asked me to try brute-forcing, as he had been looking for this solution without luck. This is the only solution the brute-forcer found, and I do believe it is the one and only shortest solution in Cubix.
Single program
Watch it run!
The original program fits on a unit cube. Here's the unfolded net:
)
< @ O P
.
The IP (instruction pointer) starts on the leftmost face (the <
) headed east. The <
immediately points it west, and it wraps around to the P
. P
is exponentiation, and since there's nothing on the stack, the interpreter pulls out two 0s and calculates 00, which is 1 according to JavaScript. O
then prints this value, and @
ends the program.
Double program
Watch it run!
)<@OP)<@OP
The 10-byte program is too long to fit onto a unit cube, and so it is expanded to a size-2 cube:
) <
@ O
P ) < @ O P . .
. . . . . . . .
. .
. .
As before, the IP starts out at the top-left of the left-most face. This time, the very first instruction is P
, which pushes a 1 as before. Next is )
, which increments the top item, turning it into a 2. Then <
turns the IP around, and it hits the )
again, transforming the 2 into a 3.
Here's where it gets interesting. P
raises the second-from-top item to the power of the first item, which gives 03 = 0. Then the IP wraps around to the rightmost face and passes through two no-ops .
before hitting another P
. Here we see another quirk of Cubix: binary operators (such as P
) don't remove their operands from the stack. So since the stack is now [3, 0]
, we calculate 30 = 1, which O
outputs, and @
terminates the program.
Triple program
Watch it run!
)<@OP)<@OP)<@OP
As with the double program, the triple can fit on a size-2 cube:
) <
@ O
P ) < @ O P ) <
@ O P . . . . .
. .
. .
This program starts out in the same way as the previous: P
pushes 1, )
increments, <
points the IP west, )
increments again, and P
now pushes 0. The IP is then wrapped around to the <
on the rightmost face, which does nothing since the IP is already pointed west.
Here is the one difference from the double program: the )
increments the 0 on top of the stack to a 1. When P
performs its magic again, this time it calculates 31 = 3. O
outputs and @
terminates, and we prove conclusively that the third time is indeed the charm.
int i=1;print i;
) then the duplicated code of (int i=1;print i;int i=1;print i;
) must output the same number as the original code, and when the code is triplicated to (int i=1;print i;int i=1;print i;int i=1;print i;
) it must show the number multiplied by 3 \$\endgroup\$