The three rules of Ruby Q. 2:
Please do not post any solutions or spoiler discussion for this
quiz until 48 hours have passed from the time on this message.
Support Ruby Q. 2 by submitting ideas as often as you can!
Suggestion: A [QUIZ] in the subject of emails about the problem
helps everyone on Ruby T. follow the discussion. Please reply to
the original quiz message, if you can.
Since next week is the Thanksgiving holiday here in the U.S., and
since I will be away visiting family, this quiz has a duration of two
weeks. It will be summarized on/about Thurs, December 4th.
Your task for these two weeks is to write a Befunge-93
interpreter. Befunge-93 is an esoteric programming language created by
Chris Pressey. Its features:
- two-dimensional program space (i.e. 80x25 ASCII grid)
- a program counter capable of moving through the program in four
- an integer stack for performing RPN-type calculations
- can be self-modifying
Basically, the program counter (PC) starts in the upper-left cell of
the program, initially moving to the right. At each cell, the command
(i.e. a single character) in that cell is executed. Some commands can
change the PC’s direction of movement; some commands put values on the
stack or operate on the stack, and a few commands accept input or
The specification, at the bottom, contains a summary of commands.
Note that the digits 0-9, not mentioned in the table of command but
mentioned earlier in the spec, push themselves onto the stack. To get
other values on the stack, you have a couple options. Mathematical
operations is one way:
Assuming the PC is moving right and starting at the left side, this
will leave 65 on the stack. Another way is stringmode, initiated and
terminated by quotes. The following also puts 65 on the stack:
At the Befunge-93 examples page, there are plenty of sample
programs for you to test, documented with the program’s intent. Some
programs were re-written by various developers in an attempt to shrink
programs as much as possible. In particular, the “rand” series
(generate a random number from 1 to 16) went through 16 revisions,
going from 144 cells (12x12) to a mere 16 cells (16x1). My own
submission was king for barely an hour, and looked like this:
> v < vv # < 14 >0^ +*v?1^ + >2^p . > 3^1 @>"<"1^
Some of the most interesting (i.e. insane) Befunge programs include
life.bf, mandel.bf, pi2.bf, and wumpus.bf.