Wednesday, August 28, 2013

Return to Problem 12...In Shakespeare!

After spending about 5 days writing my Shakespeare compiler (Nota Bene: I did do other things on those days), I was pretty familiar with the language, and it didn't take terribly long to port my solution to Project Euler problem 12 from Go to Shakespeare. At first I was thinking I would port problem 10 (I used ML before, it asks for the sum of all primes below 2 million), but that seemed too easy as I spent most of today debugging my compiler's interaction with an example prime-sieve program. So, instead, I solved Problem 12, in which I had to find the first triangle number with over 500 divisors - and now I will get to use Go again, and Go was fun (in the easy way, not the way in which Shakespeare is fun). I quite like my solution - in runs quickly, it has plenty of Shakespearean characters, etc, etc - After writing a program in Shakespeare, I definitely agree with the suggestion someone gave me earlier that saying "let us return to scene X" in the dialog is kind of silly...I may add a feature that allows using descriptive scene names if I decide to go back to my compiler any time soon. This didn't take too long to write, other than multiple times when I forgot what data Juliet, Julia, Ophelia, etc were supposed to represent.

Anyway, the source code (for anyone interested, the compiled C code: https://dl.dropboxusercontent.com/u/34972177/PELC/e12.c):
The Tale of the 12th Euler.

Juliet, a young woman with a love for triangles.
Ophelia, another young woman who loves factors.
Octavia, a young woman who holds a big number.
Macbeth, a temporary young man who likes roots.
Romeo, a man who likes counting (and Juliet).
Julia, a young woman who also counts.

    Act I: Some smalltalk (not the Squeak kind)

    Scene I: Octavia's Initialization.

[Enter Juliet and Octavia]

Juliet:
    You cute beautiful amazing sweet sunny trustworthy gentle 
    golden good girl! You are as pretty as the difference between 
    thyself and the sum of a brave charming bold noble warrior and 
    the evil dirty devil!

Octavia:
 You are a pretty girl too, thanks much for the accolades.

[Exeunt]
[Enter Macbeth and Romeo]
  
    Act II: A non-trifling time

    Scene I: Getting to work

Macbeth:
    You are as cunning as the sum of thyself and a hero.

[Exit Macbeth]

[Enter Juliet]
Romeo:
    You are as lovely as the quotient of the product of myself 
    and the sum of myself and Heaven and a good King!

[Exit Juliet]

[Enter Macbeth]
Romeo:
    You are as prompt as the square root of Juliet!
[Exit Macbeth]

[Enter Ophelia]
  
    Scene II: Getting ready to factor.

Romeo: 
 You are nothing at all.

Ophelia: 
 Is the square of Macbeth as noble as Juliet?

Romeo: 
 If so, you are as beautiful as a flower.

[Exit Romeo]
[Enter Julia]

Ophelia: 
 You are an angel.


    Scene III: Time for real factoring.

Ophelia: 
 Is the remainder of the quotient between Juliet and thee better than nothing?
         
Julia:
 If not, you are as pretty as the sum of thyself and a golden flower.

Ophelia:
 You are as cute as the sum of yourself and a plum. 
 Art thou more pretty than Macbeth?

Julia:
 If so, let us proceed to Scene IV. If not, let us return to Scene III.

    Scene IV: The Final Judgment (or going back for more work).

[Exeunt]
[Enter Romeo and Ophelia]

Romeo:
 Are you more pretty than Octavia?

Ophelia:
 If so, let us proceed to Scene V.

[Exit Ophelia]
[Enter Macbeth]

Macbeth:
 Let us return to Scene I.

    Scene V: The Answer is Printed.

[Exeunt]
[Enter Juliet and Ophelia]

Ophelia: 
 Open Your Heart!

Juliet: 
 You are as beautiful as the product of a good man and the sum 
 of the lord and a cute golden girl. Speak Your Mind!

[Exeunt]

No comments:

Post a Comment