Lost is a 2-D programming language where the start position and direction of the ip are entirely random.
Today we will be writing a Lost program which uses this randomness to simulate a coin flip.
A coin flip can have 3 outcomes:
- It lands on "heads"
- It lands on "tails"
- It lands perfectly balanced on the side
To simulate these outcomes your program should output:
- "Heads!"
- "Tails!"
- "Side?!"
Heads and tails are equally likely while landing on the side is extremely unlikely, so your program should output "Heads!" about as often as it outputs "Tails!", specifically of all the possible start states the number of heads and tails should differ by at most 1. The side is extremely unlikely so of all the possible start conditions exactly 1 should output "Side?!" when run.
No other output should occur, and your program should deterministically halt.
Answers must be in Lost. To simulate all the outputs you should run your program with the -Q
flag.
You may assume no input is passed to the program.
This is code-golf, so the goal is to minimize the size of your program as measured in bytes.
Description of Lost
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
Jumps
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
Operations
+
Adds the top two numbers
*
Multiplies the top two numbers
-
Multiplies the top by -1
Flow
\
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
Control