Lost is a 2-Dimensional programming language where the instruction pointer starts at a random location, moving in a random direction. A description of the language can be found at the bottom of the post for completeness' sake and a tutorial for the language can be found in the above link.

The task here is simple to describe: Write a non-empty lost program which when run will output the direction that was selected at the beginning of execution.

The four directions are:

  • N for north
  • E for east
  • S for south
  • W for west

You may output them with any capitalization you please and with an optional trailing newline.


Lost operates on a grid where each instruction is a character of the source. Lost's instruction pointer (ip) moves through the grid in one of the four cardinal directions. When it goes off one side of the grid it wraps around to the other as if the program were written on a torus.

Lost's memory is stored in a main stack and a scope. Both are stacks padded with zeros at the bottom. At the end of execution the contents of the main stack are printed and the scope discarded. Lost also stores a single value called the "safety", which begins on.

Programs can only terminate when the safety is off.


  • [ Reflects the ip if it is moving east; becomes ] if the ip is moving horizontally

  • ] Reflects the ip if it is moving west; becomes [ if the ip is moving horizontally


  • ! Skips the next operation

  • ? Pops off the top of the stack and jumps if not zero

Stack manipulation

  • : Duplicates the top of the stack

  • $ Swaps the top two items of the stack

  • ( Pops from the stack and pushes to the scope

  • ) Pops from the scope and pushes to the stack


  • 0-9 pushes n to the top of the stack

  • " Starts and ends a string literal. During a string literal commands are not run and instead their character values are pushed to the stack.


  • + Adds the top two numbers

  • * Multiplies the top two numbers

  • - Multiplies the top by -1


  • % Turns the safety off

  • # Turns the safety on

  • @ Ends execution if the safety is off (starts on)

The following operations are present in Lost but cannot be used for this challenge, since doing so instantly makes the challenge impossible.

  • \ Swaps the x and y directions

  • / Swaps the x and y directions and multiplies them by -1

  • | Multiplies the horizontal direction by -1

  • > Tells the ip to move east

  • < Tells the ip to move west

  • v Tells the ip to move south

  • ^ Tells the ip to move north

  • \$\begingroup\$ Does a Lost program have to be a rectangle? Do the unused spaces still count as bytes? \$\endgroup\$ – xnor Dec 19 '19 at 2:32
  • 1
    \$\begingroup\$ Here's a verifier that people can use to test their code \$\endgroup\$ – Jo King Dec 19 '19 at 2:47
  • \$\begingroup\$ @xnor Unused spaces only count if they is a used space after them in the same row. Other unused spaces will be padded automatically by the interpreter and do not need to be counted. \$\endgroup\$ – Wheat Wizard Dec 19 '19 at 3:15

1749 1533 bytes


Try it online! Verify it!

This works similarly to the one posted in chat, with a shorter execution part and some extra stuff trimmed off the right edge. I've golfed about a hundred bytes off the edges, but perhaps I should look for a shorter inner section before that.

Here is a formatter that takes a few lines and formats them in this square, though some minor edits to the lines/columns with @s in them are necessary to get it actually working.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.