6 of 13
added 374 characters in body
Wheat Wizard
  • 98.7k
  • 21
  • 278
  • 649

Lost, 57 54 45 bytes

Two bytes saved thanks to @MartinEnder

v<<<<<<<<<<>>>>>>>>>>>
>%?"Hello, WorldvU"-+@

Try it online!

Explanation

Lost is a 2 dimensional language in which the start location and direction are entirely random. As you might imagine it is rather difficult to write deterministic programs in lost. However the language has a couple of design features that allow for deterministic programs to be written.

Here's how this one works:

I'll first give you some information on the operations in Lost that are important here, so you don't have to read the github. I will leave out the more obvious ones.

  • @ exits, but only if the "safety" is off. The safety begins on.

  • % turns the safety off.

  • ? Pops the TOS and jumps if it is non-zero.

  • ! jumps unconditionally.

  • ( pops a value and saves it for later.

Ok now we are read to dive in.

The main code is the following line

"Hello, WorldvU"-+@

This pushes the string Hello, WorldvU, subtracts the U from the v to get a !, and then terminates the program (we assume the safety is off)

However we have to get to this program so we create a line of arrows to catch the randomly moving pointers

v<<<<<<<<<<<<<<<<<<<<
>%"Hello, WorldvU"-+@

We also add a % to turn the safety off once we have corralled the programs. We can now see that the v is in the string to redirect ips that start inside the string.

Our last problem is that we sometimes accumulate garbage we don't want in our final product before we arrive at the start of execution. To fix this we just eat everything on the stack that is not zero (this only works because the garbage never contains a zero).

v<<<<<<<<<<<<<<<<<<<<<<<
>%?!<"Hello, WorldvU"-+@

The code >&?!< acts our loop, discarding values until it discards a zero.

This doesn't work because the ! can jump to itself over the top or bottom of the program when the ip starts on it moving either up or down. This will cause an infinite loop (this is the same reason we didn't include ! in the original Hello, world! string). We can fix two ways. The first way, which works in most scenarios, is to another stream below to catch this specific pointer.

v<<<<<<<<<<<<<<<<<<<<<<<
>%?!<"Hello, WorldvU"-+@
^<<<

With this new stream our program has now covered all the possibilities and is deterministic.

However if we want to be a bit more clever and save a few bytes we can do away with ! entirely. We replace our loop with <%?.

v<<<<<<<<<<<<<<<<<<<<<
>%?"Hello, WorldvU"-+@

Since there is a v later on the line which sends us back to the beginning of the loop our ? will reset the loop if the top of the stack is non-zero, while if it is zero it will hit " and complete the program as intended.

Lastly I reversed some of the upper stream. This just makes the program a little faster, doesn't lose me any bytes so why not.

Alternative solution, 45 bytes

%?\>>>>>>>>>>>>>>>>>>>
>>\"Hello, WorldvU"-+@

Try it online!

This uses a slightly different collect and clear method. Same length overall.

Wheat Wizard
  • 98.7k
  • 21
  • 278
  • 649