18
\$\begingroup\$

Lost is a 2-D programming language where the start position and direction of the ip are entirely random.

This makes it very difficult to make deterministic Lost programs. However today we are not writing a deterministic program, we are writing an RNG.

Write a Lost program that takes no input and outputs a single digit (0,1,2,3,4,5,6,7,8, or 9), with all digits having an equal probability of being output. Since Lost's start location and direction is the only source of randomness, the only way to do this is to have every location in your source output a different number from 0 to 9 with an equal number outputting each digit.

You can calculate the probability of each digit by using the -Q flag and piping it into this python script

import sys
a=sys.stdin.read().split()[:-1]
for x in range(10):print x,':',a.count(`x`)
print[x for x in a if x not in list("1234567890")]

Try it online!

This is so answers will be scored in bytes with less bytes being better.


An overview of Lost

Lost is a wrapping implicit IO 2D language taking much from the mold of Klein. Here is a quick cheatsheet of what lost commands do

  • \,/,| Mirrors the ip

  • <,^,>,v Points the ip in a direction

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

  • : 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)

\$\endgroup\$
7
  • \$\begingroup\$ What happens if you try to swap two values from the stack but there is only one value or try to pop from an empty stack? \$\endgroup\$ Commented Aug 9, 2017 at 17:01
  • \$\begingroup\$ @ppperry The stack is padded with implicit zeros. \$\endgroup\$
    – Wheat Wizard
    Commented Aug 9, 2017 at 17:02
  • 1
    \$\begingroup\$ Too low information about language. Does it wrap? What 'safety' means? Bracets description is misleading? How scope is used? \$\endgroup\$ Commented Aug 10, 2017 at 9:21
  • \$\begingroup\$ @DeadPossum I tried to keep it concise. It does wrap. Safety is already explained in the question. I don't know what you mean about the brackets. [] act as doors, <> point in directions and () store and recall from the scope. Scope is used to store values. \$\endgroup\$
    – Wheat Wizard
    Commented Aug 10, 2017 at 13:05
  • \$\begingroup\$ @WheatWizard So safety is just condition for @ or does it have other usecases? About brackets, I don't understand this part: becomes ] if the ip is moving horizontally. Moving east is horizontally too, isn't it? \$\endgroup\$ Commented Aug 10, 2017 at 13:43

2 Answers 2

14
\$\begingroup\$

81 101 bytes

This might be golfable further ...

>%(0@>%(1@>%(2@>%(3@>%(4@>%(5@>%(6@>%(7@>%(8@>%(9@
^<<<<^<<<<^<<<<^<<<<^<<<<^<<<<^<<<<^<<<<^<<<<^<<<<

Try it online!

\$\endgroup\$
9
  • 1
    \$\begingroup\$ Interesting approach! I hadn't thought of that \$\endgroup\$
    – Wheat Wizard
    Commented Aug 9, 2017 at 17:00
  • 1
    \$\begingroup\$ 101 bytes that fixes the double print. Just added a stack pop before the safety is turned off so if you hit the number at the start, it can pop it, push it again, then die. I don't know if this is still technically a uniform random though... \$\endgroup\$ Commented Aug 9, 2017 at 17:07
  • 1
    \$\begingroup\$ I literally came up with the same idea at the same time ... \$\endgroup\$ Commented Aug 9, 2017 at 17:09
  • 1
    \$\begingroup\$ Your output isn't uniform. 0 has a 7/101 chance of being printed (any of the < or ^ underneath its block, plus the > and % symbol), 1-8 have a 10/101 chance, and 9 has a 11/101 chance. Then it looks like there might be a chance it just goes on forever. \$\endgroup\$ Commented Aug 9, 2017 at 17:19
  • 1
    \$\begingroup\$ It has to wrap, or otherwise this would terminate when it starts on the top line going up. \$\endgroup\$ Commented Aug 9, 2017 at 17:21
13
\$\begingroup\$

Lost, 54 bytes

>%(0@>%(1@
@>%(2@>%(3
5@>%(4@>%(
(7@>%(6@>%
%(9@>%(8@>

Try it online!

Just copied from pppery's answer and do some random stuff. I know nothing about Lost language. And I even do not know what happening for above codes. Is this work? (I don't know)

\$\endgroup\$
2
  • \$\begingroup\$ Your code produces half as much output as ppperry's, I guess it's because of how -Q works? The output seems normally distributed anyway. It would have been nice to have a full spec of the language linked in the question. \$\endgroup\$
    – Aaron
    Commented Aug 10, 2017 at 9:22
  • 1
    \$\begingroup\$ @Aaron I should have explained how -Q works. Since the language is random, verification is done by running all the possibilities. -Q does this and prints all the results. The shorter the program the less possibilities there are and the fewer outputs come from -Q. \$\endgroup\$
    – Wheat Wizard
    Commented Aug 11, 2017 at 15:15

Your Answer

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

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