This program parses 332682811
as a little-endian base-9 integer and prints it in base-10.
Befunge interprets instructions on a 2D grid (or torus, depending on version), with an instruction pointer that can move freely in two dimensions. This program is a one-liner, so the instruction pointer only moves forward and backward.
9332682811
pushes those digits individually onto Befunge's value stack, and then the following instructions perform a simple loop. In a normal iteration of the loop, things look like this:
Instructions Meaning Top stack values
9332682811>\#+:#*9-#\_$.@
> Set the instruction pointer to travel a b
to the right.
\ Swap the top 2 values on the stack. b a
#+ Nothing, since # means b a
skip the next instruction.
: Duplicate the top value on the stack. b a a
9 Push 9. b a a 9
- Pop two values and push their difference. b a (a-9)
_ Pop the top value and set the instruction b a
pointer traveling right if the value is 0
or left otherwise.
\ Swap the top 2 values. a b
9 Push 9. a b 9
* Pop two values and push their product. a (b*9)
+ Pop two values and push their sum. (b*9 + a)
> Set the instruction pointer traveling
right again.
So unless the second value on the stack at the start of an iteration is 9, the iteration pops two values b
and a
and pushes b*9 + a
.
If the second value is 9, the loop terminates and prints the top value:
Instructions Meaning Top stack values
9332682811>\#+:#*9-#\_$.@
_ Pop the top value and set the instruction b a
pointer traveling right if the value is 0
or left otherwise.
$ Discard the top value. b
. Pop and print the top value.
@
So, in summary, the program pushes a bunch of digits and repeatedly replaces a
and b
with b*9+a
until it hits 9, the signal to stop. This is a base 9 converter.
If you try to verify this with another base converter, make sure you get the endianness right. 332682811
is little-endian, so you may need to reverse it.