Proven optimal!
((([()][()][()])))
Try it online!
Explanation
Brain-Flak, Brain-Flueue, Miniflak, and Fλak
([()][()][()]) Push -3
( ) Copy
( ) Copy
This prints:
-3
-3
-3
(There is a trailing newline)
Brain-Flak Classic
Brain-Flak Classic is the original version of Brain-Flak and has some important differences from modern Brain-Flak. In BFC [...]
prints its contents rather than negating it.
[()] Print 1
[()] Print 1
[()] Print 1
( ) Push 3
( ) Push 3
( ) Push 3
At the end of executing the contents of the stack (3 3 3
) is printed.
This prints:
1
1
1
3
3
3
(There is a trailing newline)
Flakcats
Flakcats is quite different from the other 4 flaks and I am surprised that this works in Flakcats. The three operators here are nearly the same as the ones that Brain-Flak uses.
The main difference in this particular program between Flakcats is the (...)
operator which in Flakcats is equivalent to ([{}]...)
in Brain-Flak. This however does not make a difference to us because it picks up zeros and thus operates much in the same way that Brain-Flak does.
Here is that program compiled into Brian-Flak:
([{}]([{}]([{}][()][()][()])))
This prints:
-3
-3
-3
(There is a trailing newline)
Proof of Optimality in Brain-Flak and Miniflak
This is not a formal proof, but rather an informal proof that would have to be expanded to be made more rigorous
Because of the restrictions that Brain-Flak programs must be a balanced-string and the program length must be a multiple of 3 any valid submission must be a multiple of 6 in length. This means any solution smaller than 18 must be length 12.
Because of the outputs trailing newline the final height of the stack must be a multiple of three or we will break the restrictions on output.
Any valid submission of length 12 must have 2 types of braces (having less would break the restrictions on number of distinct characters and more would mean more than 12 characters). Since the program produces output it must have a push.
This leaves us to select our other set of braces. The options are:
<...>/<>
This fails because we need to generate "value" in order to create any number other than zero we must give up a ()
to create a one which makes it impossible to push more than two times.
[...]/[]
This fails for the same reason the last failed. The square braces are really bad at making value. The []
monad can create value but we need to push numbers first and we then don't have enough parens left over to push three times.
{...}/{}
This one is promising, we could create a loop and use one ()
to push multiple times, but alas it is not possible.
In order for the loop to end there must be a zero on the stack at some point and in order for us to have the correct output we must have something other than zero on the stack at the end of the program. Since we have neither []
nor <>
the zero at the end of the loop must be a implicit zero from the bottom of the stack. This means the loop cannot add any new numbers to the stack making it useless.
Since none of the brace choices can create a program of length 12 none can exist.
Since Miniflak is a subset of Brain-Flak any shorter Miniflak program would also be a shorter Brain-Flak program and thus does not exist.
Brain-Flueue is a joke language based off of Brain-Flak. The two are so similar their interpreters are identical everywhere but two lines. The difference between the two is, as their names suggests, Brain-Flueue stores its data in queues while Brain-Flak stores its data in stacks.
To start we have the same restrictions on program size created by Brain-Flak, thus we are looking for a program of size 12. In addition we are going to need a (...)
in order to create any output and another pair. the <>
and []
pairs do not work in Brain-Flueue for the exact same reason they do not work in Brain-Flak.
Now we know that our program must consist of the characters ((())){{{}}}
.
Via the same methods used in the previous proof we can demonstrate that there must be a loop in the final program.
Now here is where the proofs differ, because Brain-Flueue operates across queues rather than stacks the program can exit a loop with values on the queue.
In order to exit the loop we will need a zero in the queue (or an empty queue but if the queue is empty we get the same problem as Brain-Flak) this will mean that we will have to open our program with ({})
to create the zero. We will need a push inside of the loop to push the necessary number of items to the queue. We will also need to push a non zero number before the loop so that we can enter the loop at all; this will cost us at absolute minimum (())
. We have now used more parens than we have.
Thus there is no Brain-Flueue program to do the task that is 12 bytes, and furthermore there our program is optimal.
The following solution is optimal in Flakcats and Brain-Flak Classic.
((([][][])))
Explanation
[][][] -3
((( ))) push 3 times
Alternative 24 byte Brain-Flak solutions
(<((<((<(())>)())>)())>)
Try it online!
((<((<((<>)())>)())>)())
Try it online!
((((((()()()){}){}){})))
Try it online!
123123123
will work, as currently written.) \$\endgroup\$abcabcabc
with a trailing newline? \$\endgroup\$