Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

added 1063 characters in body
Source Link
user202729
  • 17.6k
  • 2
  • 39
  • 71

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 if shift(D) = shift(E) = 0 then the program B executed either forward or backward would add a fixed value to the current cell before printing the second time, which can't be the case because ord('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 if shift(D) = shift(E) = 0 then the program B executed either forward or backward would add a fixed value to the current cell before printing the second time, which can't be the case because ord('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.

Source Link
user202729
  • 17.6k
  • 2
  • 39
  • 71

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)

AltStyle によって変換されたページ (->オリジナル) /