From: Matthew Moss Date: 2008-11-23T01:55:53+09:00 Subject: [QUIZ] Befunge (#184) -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- The three rules of Ruby Quiz 2: 1. Please do not post any solutions or spoiler discussion for this quiz until 48 hours have passed from the time on this message. 2. Support Ruby Quiz 2 by submitting ideas as often as you can! Visit . 3. Enjoy! Suggestion: A [QUIZ] in the subject of emails about the problem helps everyone on Ruby Talk follow the discussion. Please reply to the original quiz message, if you can. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- ## Befunge (#184) 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][1] 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 directions * 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 print output. The [specification][2], 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: 562**5+ 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: "A" At the [Befunge-93 examples page][3], 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. [1]: http://catseye.tc/projects/befunge93/ [2]: http://catseye.tc/projects/befunge93/doc/befunge93.html [3]: http://catseye.tc/projects/befunge93/eg/INDEX.html [4]: http://catseye.tc/projects/funge98/