Lost -A
, 113 bytes
>%?"Stack Exch2/"+\"nge Chat"@
^/+"/% - tahC egn"<
?>"he Nineteenth Byt6/"+@v
^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
^<<"
The 19th byte is the \
on the first line.
Try it online or verify that it's deterministic.
Try it online without 19th byte or verify that that is deterministic.
Explanation:
Explanation of the language in general:
Lost is a 2D path-walking language. Most 2D path-walking languages start at the top-left position and travel towards the right by default. Lost is unique however, in that both the start position AND starting direction it travels in is completely random. So making the program deterministic, meaning it will have the same output regardless of where it starts or travels, can be quite tricky.
A Lost program of 2 rows and 5 characters per row can have 40 possible program flows. It can start on any one of the 10 characters in the program, and it can start traveling up/north, down/south, left/west, or right/east.
In Lost you therefore want to lead everything to a starting position, so it'll follow the designed path you want it to. In addition, you'll usually have to clean the stack when it starts somewhere in the middle.
Explanation of the program:
All arrows, including the reflects /
in the strings, will lead the path towards the leading >
on the first line. From there the program flow is as follows:
>
: Travel towards the right
%
: Put the safety 'off'. In a Lost program, an @
will terminate the program, but only when the safety is 'off'. When the program starts, the safety is always 'on' by default, otherwise a program flow starting at the exit character @
would immediately terminate without doing anything. The %
will turn this safety 'off', so when we now encounter an @
the program will terminate (if the safety is still 'on', the @
will be a no-op instead).
?
: Clean the top value on the stack. In some program flows it's highly likely we have a partial string on the stack, so we use this to wipe the stack clean of that potential string. (Minor note: if the stack was not empty when ?
is encountered, the next operation will be skipped.)
"
: Start a string, which means it will push the integer code-points of the characters used.
Stack Exch2/
: Push the code-points for these characters, being 83 116 97 99 107 32 69 120 99 104 50 47
respectively
"
: We're done pushing code-points of this string
+
: Add the top two values together: (50+47=) 97
- With 19th byte:
\
: Reflect the direction downwards
<
: Change the direction towards the left
"
: Start a string again
nge Chat - %/
: Push the code-points 110 103 101 32 67 104 97 116 32 45 32 37 47
"
: We're done pushing code-points again
+
: Add the top two values together: (37+47=) 84
/
: Reflect the direction downwards
>
: Change the direction towards the right
"he Nineteenth Byt6/"+
: The same yet again
@
: Terminate the program if the safety is 'off' (which it is at this point). After which all the values on the stack will be output implicitly. Using the -A
program argument flag, these code-points will be output as characters instead.
- Without the 19th byte:
"nge Chat"
: Push the code-points 110 103 101 32 67 104 97 116
@
: Similar again: terminate the program if the safety is 'off' (which it is at this point), and output the values on the stack implicitly (as characters because of the -A
flag).
Some things to note:
- The leading
?
on the third line instead of a ^
is to clean a second unwanted value from the stack, which happens (among others) for the flow {first row, third character, traveling downwards}.
- The bottom row
^<<"
, and primarily the "
, is for the flow {first row, fourth character, traveling upwards}, which would otherwise keep pushing strings without changing directions.
- The trailing
v
on the third line is for the flow {first row, third character, traveling right}, which skipped the %
to put the safety off, and would end up in an infinite loop traveling left on the third line.
- The
/
in the strings are to prevent infinite loops as well. The one in "Stack Exch2/"+
for flow {first row, second character, traveling downward}; the one in "/% - tahC egn"
for flow {second row, fourth character, traveling left}; and the one in "he Nineteenth Byt6/"
for flow {third row, third character, traveling left}.