Lost, 52 bytes
vvvvvvvvvvvvvvvvv
<v<<<<<<<<<<<<<<<
@>%?!<7>2!.-!.+[
Try it online!
vvvvvvvvvvvvvvvvv
<v<<<<<<<<<<<<<<<
@>%?!<7>2!.-!.+[[
Try it online!
Explanation
Lost is a language in which the start location and direction of the pointer are entirely random. Thus making a deterministic program can be tough.
The first two lines are redirects meant to funnel the stray ips into a single location. Two lines are needed because the !
s that are used on the third line need to be prevented from closing a loop. Once it exits the funnel it enters the clearing area. This code
>%?!<
serves to remove any garbage that might have been picked up before it entered the funnel. It also switches the safety off with %
. Safety is a Lost feature that prevents the program from prematurely exiting the program, it needs to be turned off in order to terminate. Since we have successfully corralled the ip where we have control it is a good time to turn the safety off.
After exiting the loop a 7 is pushed on the stack with 7
, then 2-+
subtracts 2 from the code. Each door ([
), either 1 or 2 depending on the program, runs this code again each time subtracting 2. We add some !.
s to the code so that when the ip backs up over the code nothing is harmed.
9.0
and3.0
? (Taking square roots, so it automatically turns into a float. :P) \$\endgroup\$ – totallyhuman Aug 27 '17 at 1:02