brainfuck, 156 bytes
+++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++++++++++++++++++++++++++++++++<+++++++++++++++++++++++++++++++++++++++++++++++++.++++++++++
Try it online! / Forward/backward verifier in Bash
Prints -1 forward and \n1 backwards.
Despite being almost trivial, I believe this is the optimal solution for this particular fixed output.
Proof:
The program cannot have
[or].Therefore the program must have the form
<A> . <B> . <C>.Each
,can be replaced with a sufficient number of<without increasing the number of+or-.Each
+is only useful in either the forward or the backward program, never both.Proof:
+in part A is obviously only useful in the forward program, and+in part C is obviously only useful in the backward program.Denote
shift(P)= number of<in P - number of>in P. Consider program<B> = <D> + <E>, the+in the middle is useful in the forward program \$\iff\$shift(E) = 0, similarly it's useful in the backward program \$\iff\$shift(D) = 0. However ifshift(D) = shift(E) = 0then the programBexecuted either forward or backward would add a fixed value to the current cell before printing the second time, which can't be the case becauseord('1') - ord('\n') != ord('1') - ord('-').
Therefore the program needs at least (proof later)ord('-')+ord('1')+ord('\n')+ord('1') = 153+s, 2 .s, and at least a <> or , because shift(B) != 0.
brainfuck, 156 bytes
+++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++++++++++++++++++++++++++++++++<+++++++++++++++++++++++++++++++++++++++++++++++++.++++++++++
Try it online! / Forward/backward verifier in Bash
Prints -1 forward and \n1 backwards.
Despite being almost trivial, I believe this is the optimal solution for this particular fixed output. (proof later)
brainfuck, 156 bytes
+++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++++++++++++++++++++++++++++++++<+++++++++++++++++++++++++++++++++++++++++++++++++.++++++++++
Try it online! / Forward/backward verifier in Bash
Prints -1 forward and \n1 backwards.
Despite being almost trivial, I believe this is the optimal solution for this particular fixed output.
Proof:
The program cannot have
[or].Therefore the program must have the form
<A> . <B> . <C>.Each
,can be replaced with a sufficient number of<without increasing the number of+or-.Each
+is only useful in either the forward or the backward program, never both.Proof:
+in part A is obviously only useful in the forward program, and+in part C is obviously only useful in the backward program.Denote
shift(P)= number of<in P - number of>in P. Consider program<B> = <D> + <E>, the+in the middle is useful in the forward program \$\iff\$shift(E) = 0, similarly it's useful in the backward program \$\iff\$shift(D) = 0. However ifshift(D) = shift(E) = 0then the programBexecuted either forward or backward would add a fixed value to the current cell before printing the second time, which can't be the case becauseord('1') - ord('\n') != ord('1') - ord('-').
Therefore the program needs at least ord('-')+ord('1')+ord('\n')+ord('1') = 153+s, 2 .s, and at least a <> or , because shift(B) != 0.
brainfuck, 156 bytes
+++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++++++++++++++++++++++++++++++++<+++++++++++++++++++++++++++++++++++++++++++++++++.++++++++++
Try it online! / Forward/backward verifier in Bash
Prints -1 forward and \n1 backwards.
Despite being almost trivial, I believe this is the optimal solution for this particular fixed output. (proof later)