13
\$\begingroup\$

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.

Description

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.

Doors

  • [ 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

Jumps

  • ! 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

Literals

  • 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.

Operations

  • + Adds the top two numbers

  • * Multiplies the top two numbers

  • - Multiplies the top by -1

Control

  • % 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

\$\endgroup\$
3
  • \$\begingroup\$ Does a Lost program have to be a rectangle? Do the unused spaces still count as bytes? \$\endgroup\$
    – xnor
    Dec 19, 2019 at 2:32
  • 1
    \$\begingroup\$ Here's a verifier that people can use to test their code \$\endgroup\$
    – Jo King
    Dec 19, 2019 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, 2019 at 3:15

2 Answers 2

11
\$\begingroup\$

1749 1533 bytes

%(6.99*+@+6*97(((((%#%%%%%%%#%%#%%%%%
%(((((99*6+@+*976((%%(((((((%((%(((((
%((699*+@+6*97(((((%((((((((((((((((((((
%(((((99*6+@+*976((%2(2(2(2(2(2(2(2(2(2(
%((699*+@+6*97(((((%9(9(9(9(9(9(9(9(9(9(
%(((((99*6+@+*976((%9(9(9(9(9(9(9(9(9(9(
%((699*+@+6*97(((((%*9*9*9*9*9*9*9*9*9*9
%(((((99*6+@+*976((%+9+9+9+9+9+9+9+9+9+9
#%(699*+@+6*97((((%#@*@*@*@*@*@*@*@*@*@*
%(((((99*6+@+*976((%+2+2+2+2+2+2+2+2+2+2
%((699*+@+6*97(((((%6+6+6+6+6+6+6+6+6+6+
(#%(((99*6+@+*976(%#*@*@*@*@*@*@*@*@*@*@
%((699*+@+6*97(((((%8+8+8+8+8+8+8+8+8+8+
(%((((99*6+@+*976((%9*9*9*9*9*9*9*9*9*9*
%((699*+@+6*97(((((%(8(8(8(8(8(8(8(8(8(8
(((%((99*6+@+*976((%(9(9(9(9(9(9(9(9(9(9
(((699*+@+6*97(((((%(6(6(6(6(6(6(6(6(6(6
2(((((99*6+@+*976((%((((((((((((((((
((69.9*+@+6*97(((((%((((((((%((%((
%(((%(99*6+@+*976((%%%%%%%%%#%%#
+6.*97%%#%%#%%%%%%%((((699*+@
*976((((%((%((((((((%(((((99*6+@+
((((((((((((((((((((%((699*+@+6*97(
2(2(2(2(2(2(2(2(2(2(%(((((99*6+@+*976(
9(9(9(9(9(9(9(9(9(9(%((699*+@+6*97(((
9(9(9(9(9(9(9(9(9(9(%(((((99*6+@+*976(
*9*9*9*9*9*9*9*9*9*9%((699*+@+6*97(((
+9+9+9+9+9+9+9+9+9+9%(((((99*6+@+*976(%
@*@*@*@*@*@*@*@*@*@*#%(699*+@+6*97(((%#
+2+2+2+2+2+2+2+2+2+2%(((((99*6+@+*976((%
6+6+6+6+6+6+6+6+6+6+%((699*+@+6*97(((
*@*@*@*@*@*@*@*@*@*@#%((((99*6+@+*976(%#
8+8+8+8+8+8+8+8+8+8+%((699*+@+6*97(((
9*9*9*9*9*9*9*9*9*9*%(((((99*6+@+*976((%
(8(8(8(8(8(8(8(8(8(8%((699*+@+6*97(((
(9(9(9(9(9(9(9(9(9(9%(((((99*6+@+*976
(6(6(6(6(6(6(6(6(6(6%((699*+@+6*97((
6(((((((((((((((((((%(((((99*6+@+*97
7.9(((((%((%((((((((#%(699*+@+6*
+*976%(%#((#%(9.9*6+@

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.

\$\endgroup\$
7
\$\begingroup\$

504 503 bytes

+6*9+ 18((%(( 77*54*+@
6*9+-09((%(( 99*54*+@+
*9+ 18((%(( 77*54*+@+6
9+-09((%(( 99*54*+@+6*
+ 18((%(( 77*54*+@+6*9
-09((%(( 99*54*+@+6*9+
18((%(( 77*54*+@+6*9+
9((%(( 99*54*+@+6*9+-0
((%(( 77*54*+@+6*9+ 18
(%(( 99*54*+@+6*9+-09(
%(( 77*54*+@+6*9+ 18((
(( 99*54*+@+6*9+-09((%
( 77*54*+@+6*9+ 18((%(
 99*54*+@+6*9+-09((%((
77*54*+@+6*9+ 18((%((
9*54*+@+6*9+-09((%(( 9
*54*+@+6*9+ 18((%(( 77
54*+@+6*9+-09((%(( 99*
4*+@+6*9+ 18((%(( 77*5
*+@+6*9+-09((%(( 99*54
+@+6*9+ 18((%(( 77*54*
@+6*9+-09((%(( 99*54*+

Try it online!

After a % is reached, switching off the safety, there are enough (s to empty the stack. Next:

Going east:  99*54*+@  produces 101 (e)
             77*54*+@  produces  69 (E)
Going south: 97*54*+@  produces  83 (S)
             79*54*+@  produces  83 (S)
Going west:  90-+9*6+@ produces  87 (W)
             81 +9*6+@ produces  87 (W)
Going north: 91-+9*6+@ produces  78 (N)
             80 +9*6+@ produces  78 (N)

-1 by removing one (, allowing one more line to be one byte shorter.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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