r?<?
"< <@,ka"I survived!
=
Try it online!
Errors with a segmentation fault.
Explanation
Befunge-98 adds some extra features (r
, k
, and =
) that can be used to further golf Joe K's Befunge-93 answer.
The first line (r?<?
) calculates the 1/6 chance. The r
initially reflects the IP to the left, where it reaches the second ?
and goes in a random direction. If it goes right, the r
reflects it and it tries again. If it goes up or down, it moves onto the second line, and if it goes left, it moves onto the first ?
. There are three ways the IP can leave, so there is a 1/3 chance it moves onto the first ?
.
If it gets there, it again goes in a random direction. If it goes horizontally, it gets reflected (with either r
or <
) and tries again. This means that there are only two ways that the IP can leave, and they are equally likely. Either it goes down onto the second line, or it goes up and hits the =
on the third line.
There is a 1/6 chance that =
is executed (1/3 from the second ?
times 1/2 from the first). If it is, it does a system-execute call on the stack (which is empty and interpreted as an empty string). FBBI's implementation of this runs a C system()
call on the empty string, which segfaults.
This leaves a 5/6 chance that the IP reaches the second line. If it does, it gets sent left with <
, and pushes the string "!devivrus I"
onto the stack. ak,
prints the top 11 characters of the stack, outputting I survived!
Finally, @
ends the program.
randrange(5)
might be implemented asrandrange(MAX_INT)%6
. \$\endgroup\$