Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
added 42 characters in body
Source Link
Martin Ender
  • 198.2k
  • 67
  • 455
  • 998

LabyrinthLabyrinth, 2 bytes

,.

If the stream is finite, this will terminate with an error, but all the output produce by the error goes to STDERR, so the standard output stream is correct.

As in Brainfuck , reads a byte (pushing it onto Labyrinth's main stack) and . writes a byte (popping it from Labyrinth's main stack).

The reason this loops is that both , and . are "dead ends" in the (very trivial) maze represented by the source code, such that the instruction pointer simply turns around on the spot and moves back to the other command.

When we hit EOF , pushes -1 instead and . throws an error because -1 is not a valid character code. This might actually change in the future, but I haven't decided on this yet.


For reference, we can solve this without an error in 6 bytes as follows

,)@
.(

Here, the ) increments the byte we read, which gives 0 at EOF and something positive otherwise. If the value is 0, the IP moves straight on, hitting the @ which terminates the program. If the value was positive, the IP will instead take a right-turn towards the ( which decrements the top of the stack back to its original value. The IP is now in a corner and will simply keep making right turns, printing with ., reading a new byte with ., before it hits the fork at ) once again.

Labyrinth, 2 bytes

,.

If the stream is finite, this will terminate with an error, but all the output produce by the error goes to STDERR, so the standard output stream is correct.

As in Brainfuck , reads a byte (pushing it onto Labyrinth's main stack) and . writes a byte (popping it from Labyrinth's main stack).

The reason this loops is that both , and . are "dead ends" in the (very trivial) maze represented by the source code, such that the instruction pointer simply turns around on the spot and moves back to the other command.

When we hit EOF , pushes -1 instead and . throws an error because -1 is not a valid character code. This might actually change in the future, but I haven't decided on this yet.


For reference, we can solve this without an error in 6 bytes as follows

,)@
.(

Here, the ) increments the byte we read, which gives 0 at EOF and something positive otherwise. If the value is 0, the IP moves straight on, hitting the @ which terminates the program. If the value was positive, the IP will instead take a right-turn towards the ( which decrements the top of the stack back to its original value. The IP is now in a corner and will simply keep making right turns, printing with ., reading a new byte with ., before it hits the fork at ) once again.

Labyrinth, 2 bytes

,.

If the stream is finite, this will terminate with an error, but all the output produce by the error goes to STDERR, so the standard output stream is correct.

As in Brainfuck , reads a byte (pushing it onto Labyrinth's main stack) and . writes a byte (popping it from Labyrinth's main stack).

The reason this loops is that both , and . are "dead ends" in the (very trivial) maze represented by the source code, such that the instruction pointer simply turns around on the spot and moves back to the other command.

When we hit EOF , pushes -1 instead and . throws an error because -1 is not a valid character code. This might actually change in the future, but I haven't decided on this yet.


For reference, we can solve this without an error in 6 bytes as follows

,)@
.(

Here, the ) increments the byte we read, which gives 0 at EOF and something positive otherwise. If the value is 0, the IP moves straight on, hitting the @ which terminates the program. If the value was positive, the IP will instead take a right-turn towards the ( which decrements the top of the stack back to its original value. The IP is now in a corner and will simply keep making right turns, printing with ., reading a new byte with ., before it hits the fork at ) once again.

Source Link
Martin Ender
  • 198.2k
  • 67
  • 455
  • 998

Labyrinth, 2 bytes

,.

If the stream is finite, this will terminate with an error, but all the output produce by the error goes to STDERR, so the standard output stream is correct.

As in Brainfuck , reads a byte (pushing it onto Labyrinth's main stack) and . writes a byte (popping it from Labyrinth's main stack).

The reason this loops is that both , and . are "dead ends" in the (very trivial) maze represented by the source code, such that the instruction pointer simply turns around on the spot and moves back to the other command.

When we hit EOF , pushes -1 instead and . throws an error because -1 is not a valid character code. This might actually change in the future, but I haven't decided on this yet.


For reference, we can solve this without an error in 6 bytes as follows

,)@
.(

Here, the ) increments the byte we read, which gives 0 at EOF and something positive otherwise. If the value is 0, the IP moves straight on, hitting the @ which terminates the program. If the value was positive, the IP will instead take a right-turn towards the ( which decrements the top of the stack back to its original value. The IP is now in a corner and will simply keep making right turns, printing with ., reading a new byte with ., before it hits the fork at ) once again.