.
Ajax,.
Ford,.
Act I:.
Scene I:.
[Enter Ajax and Ford]
Scene II:.
Ford:
Open your mind.Is sky nicer than you?If so, let us return to scene IV.
Ajax:
Open your mind.You is sum you and sum big big big big big big pig and big big big big cat!
Scene III:.
Ford:
Speak thy mind.
Ajax:
You is sum you and pig!Is you as big as zero?If so, let us return to scene II.Let us return to scene III.
Scene IV:.
[Exeunt]
Ungolfed version:
The Decoding of the Lengths of Veronan Runs - A Drama of PPCG.
Romeo, quite a character.
Juliet, Romeo's lover and multiplicand.
Act I: In which the lengths of runs are decoded.
Scene I: A silent entrance.
[Enter Romeo and Juliet]
Scene II: In which neither Romeo nor Juliet believes the other open-minded.
Juliet:
Open your mind. Is my mother jollier than thou? If so,
we must proceed to scene IV.
Romeo:
Open your mind. Thou art the sum of thyself and the sum of my good aunt and
the difference between nothing and the quotient of the square of twice the sum
of thy foul fat-kidneyed goat and thy death and thy evil variable!
Scene III: In which Romeo snaps and brutally insults Juliet.
Juliet:
Speak thy mind.
Romeo:
Thou art the sum of thyself and a hog! Art thou as rotten as nothing? If so,
let us return to scene II. Let us return to scene III.
Scene IV: Finale.
[Exeunt]
I'm using drsam94's Python SPL compiler, which has a few bugs (which is why, for instance, I use Open your mind
instead of Open thy mind
in the golfed version).
To run this program, use:
$ python splc.py rld.spl > rld.c
$ gcc rld.c -o rld.exe
$ echo -n ":144,1'1" | ./rld
:4444,'
How it works
SPL is an esoteric programming language designed to make programs look like Shakespeare plays. It does this by using characters as variables, and processing is performed by having the characters say things to one another.
The Decoding of the Lengths of Veronan Runs - A Drama of PPCG.
This is the title of the play; it's ignored by the compiler.
Romeo, quite a character.
Juliet, Romeo's lover and multiplicand.
Here we're declaring the variables used in the rest of the program. Everything betwen ,
and .
is ignored by the compiler. In this case, we declare Romeo
, used to hold the character being decoded, and Juliet
, used to hold the run length of the character.
Act I: In which the lengths of runs are decoded.
Here we declare the first and only act in the program. Acts and scenes are like labels; they can be jumped to at any time by using let us return to scene II
or some variant of that. We only use one act, because it's sufficient for our needs. Again, anything between :
and .
is ignored by the compiler.
Scene I: A silent entrance.
Here we declare the first scene. Scenes are numbered in Roman numerals: the first is Scene I
, the second Scene II
, and so on.
[Enter Romeo and Juliet]
This is a stage direction; in it, we tell the Romeo
and Juliet
variables to come onto the "stage". Only two variables can be on the "stage" at once; the stage is used so that the compiler can figure out which variable is addressing which when they speak. Because we have only two variables, Romeo and Juliet will stay onstage for the length of the program.
Scene II: In which neither Romeo nor Juliet believes the other open-minded.
Another scene declaration. Scene II will be jumped to in order to decode another run-length.
Juliet:
This form of declaration means that Juliet is going to start speaking. Everything until the next Romeo:
, stage direction, or scene/act declaration will be a line spoken by Juliet, and thus "me" will refer to Juliet, "you"/"thou" to Romeo, etc.
Open your mind.
This command stores the ordinal value of single character from STDIN in Romeo
.
Is my mother jollier than thou?
In SPL, nouns translate to either 1 or -1 depending on whether they are positive or negative. In this case, my mother
translates to 1. Adjectives (positive or negative) multiply their noun by 2.
This is a question; in it, Juliet asks if my mother
(AKA 1) is "jollier" than Romeo. Comparatives either translate to less than
(if they are negative, like worse
) or greater than
(if they are positive, like jollier
). Therefore, this question boils down to Is 1 greater than you?
.
The reason we ask this question is to detect the end of the input. Since the value of EOF
varies by platform, but is usually less than 1, we use this to detect it.
If so, we must proceed to scene IV.
If the preceding question evaluated to true
, we jump to scene IV—which is simply the end of the program. In short, if we detect an EOF, we end the program.
Romeo:
It's now Romeo's line: "me" and "you" refer to Romeo and Juliet, respectively.
Open your mind.
Again, this statement puts the ordinal value of a single character from STDIN into Juliet, which in this case is the run-length of the character stored in Romeo
.
Thou art the sum of thyself and the sum of my good aunt and the difference
between nothing and the quotient of the square of twice the sum of thy foul
fat-kidneyed goat and thy death and thy evil variable!
This one's too long to go over in great detail, but just trust me in that it translates to Juliet -= 48
. We do this because Juliet holds the ASCII value of a numeral, and ord('0') == 48
; in subtracting 48, we translate from the ASCII value of a number to the number itself.
Scene III: In which Romeo snaps and brutally insults Juliet.
Another scene declaration. This one is for the loop in which we repeatedly print the character value of Romeo
, Juliet
times.
Juliet:
Speak thy mind.
This statement causes Romeo to print his value as a character; that is, whatever character value was previously stored in Romeo is now output.
Romeo:
Thou art the sum of thyself and a hog!
A hog is a negative noun, so a hog
translates to -1; therefore, this statement evaluates to Juliet -= 1
.
Art thou as rotten as nothing?
Romeo here asks if Juliet is "as rotten as", or equal to, 0.
If so, let us return to scene II.
If Juliet's value is 0, we loop back to scene II to decode another character's run-length.
Let us return to scene III.
Else, we loop back to scene III to output Romeo's character again.
Scene IV: Finale.
[Exeunt]
This final scene declaration is just a marker for the end of the program. The [Exeunt]
stage direction is necessary to get the compiler to actually generate the final scene.
5Wow. A brainfuck solution that can compete with other solutions? – Johannes Kuhn – 2013-10-19T14:49:21.420