Lost, 30 bytes
v<<<<<<<>>>>>>>
>%?"thirt/J"+@
Contains the unprintable character ESC with unicode value 27 after the ^
on the second line. Thanks to @JoKing getting rid of the unprintable (for the same byte-count).
Try it online or verify that it's 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 reflect /
in the string, will lead the path towards the leading >
on the second line. From there the program flow is as follows:
>
: travel in an east/right direction
%
: 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.
"
: Start a string, which means it will push the integer code-points of the characters used.
thirt/J
: Push the code-points for these characters, being 116 104 105 114 116 47 74
respectively
"
: We're done pushing code-points of this string
+
: Add the top two values together: (47+74=) 121
@
: 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.
Two things to note:
The top part could also have been v<<<<<<<<<<<<<<
instead. Lost will wrap around to the other side when moving in a direction. So using v<<<<<<<>>>>>>>
could be a slightly shorter path, and since it's the same byte-count anyway, why not use it. :)
Also, the first line contains an additional trailing >
to make the byte-count from 29 to 30.
Proper spacing is also required.
Does this mean no trailing spaces in the output? \$\endgroup\$