)<@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.
Is our code allowed to read its own source code? – AdmBorkBork – 2018-03-12T13:45:27.523
@AdmBorkBork I'd assume so, since this isn't tagged as [tag:quine]. – Erik the Outgolfer – 2018-03-12T13:47:58.513
@AdmBorkBork Yes. – workoverflow – 2018-03-12T14:06:45.457
9I don't think the 1 byte restriction is needed since it wouldn't be possible to tell the difference between nothing and nothing repeated 3 times. – 12Me21 – 2018-03-13T01:42:58.823
May we print blank lines before the output in the multiplied cases? – xnor – 2018-03-13T07:02:47.707
Are we allowed leading zeroes? – Jo King – 2018-03-13T21:01:35.697
@xnor No blank lines before the output. – workoverflow – 2018-03-14T08:38:51.750
@JoKing Only if the numbers of digits is consistent eg: 001 - 001 - 003 or 004 - 004 - 012 – workoverflow – 2018-03-14T08:40:22.040
What does "the source code is duplicated" mean? – r12 – 2018-03-15T06:20:05.173
@r12 "Let's say your source code is Abc and its corresponding output is 4. If I write AbcAbc instead and run it, the output must still be 4. However if I write AbcAbcAbc and run it, the output must be 12." – workoverflow – 2018-03-15T08:46:57.933
Thank you for trying to explain it to me. I read that text several times and wasn't able to understand it. At the time, I didn't know what "Abc" was when I read the post and kept rereading it. I scrolled up and down through this post and thought "Abc" was one of these weird programming languages with unusual symbols doing unusual things. Very little on this page makes any sense to me. – r12 – 2018-03-15T19:30:27.177
1@r12 "Abc" is an example for any programming language program, say if your code is (
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 – workoverflow – 2018-03-16T16:54:07.017@r12 You should not expect to be able to understand something without learning it first. Especially on PPCG. – user202729 – 2018-03-19T09:55:06.200
Can the program print leading zero? – user202729 – 2018-03-19T10:10:06.940
@user202729 Only if the numbers of digits is consistent eg: 001 - 001 - 003 or 004 - 004 - 012 – workoverflow – 2018-03-19T21:36:11.317
I suggest adding the rule to the question instead of in the comment. / What about 4-4-12 or 04-04-12? – user202729 – 2018-03-20T01:17:40.263