42
\$\begingroup\$

What general tips do you have for golfing in The Shakespeare Programming Language? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to SPL (e.g. "remove comments" is not an answer).

Please post one tip per answer.

\$\endgroup\$
  • 17
    \$\begingroup\$ I'm not certain that you can golf SPL. SPL is so verbose that I almost feel like this question needs the code trolling tag. :P \$\endgroup\$ – Alex A. Apr 14 '15 at 19:40
  • \$\begingroup\$ You just can't golf SPL. At least, to my feeble knowledge of Shakesperian lore... \$\endgroup\$ – Rodolfo Dias Apr 14 '15 at 19:42
  • \$\begingroup\$ @RodolfoDias: Feeble? I think you're the resident Shakespeare scholar on PPCG. \$\endgroup\$ – Alex A. Apr 14 '15 at 19:44
  • 8
    \$\begingroup\$ @AlexA. Which may not be a good thing: it just means I'm demented enough to try and understand SPL :-) \$\endgroup\$ – Rodolfo Dias Apr 14 '15 at 19:48
  • \$\begingroup\$ @AlexA. Sp can do it... \$\endgroup\$ – Conor O'Brien Jan 16 '16 at 0:14

19 Answers 19

18
\$\begingroup\$

(Well... since this is my adopted language 1, I feel like I'm obliged to add something here)

Use short variable names

Yeah, yeah, yeah, that's pretty standard to code-golf, you just use one-letter-length variable names, no news here. Or is there? Because the chaps that created SPL were wacky enough not to allow any name for their language's variables: they must come from Shakesperian plays which, in terms of character length, is a pain in the royal tush - but, if you're coding in SPL, you already know that. So, my advice would be to use characters with short names, like Ajax, Ford, Page or Puck, instead of The Archbishop of Canterbury, per instance.

That's all I got, I'm afraid.


1- since my Java skills are equivalent of those of a newborn.

\$\endgroup\$
13
\$\begingroup\$

(after doing the previous one, I just remembered a few things)

Choose your code carefully

An example, to try and explain what this mean.

Ajax:
 You are as warm as a big red rich fair cute bold cat!

and

Ajax:
 Thou art as blossoming as an embroidered trustworthy bottomless peaceful charming handsome chihuahua!

produce the exact same result, which is make the character being spoken to assume the value 64 (since, assuming you read my long battle with SPL, you know that both lines are equivalent to 2*2*2*2*2*2*1); however, the first one has 59 bytes, while the second one has a bytecount of 107.

Still, no one is going to be demented enough to enter a challenge with SPL, so...

\$\endgroup\$
  • 9
    \$\begingroup\$ Could you use the same adjective multiple times in a description? E.g. a big big big big big big cat, saving 4 more bytes? I know it ruins the artistry... but this is code golf after all. ;) \$\endgroup\$ – DLosc Apr 21 '15 at 2:49
  • \$\begingroup\$ @DLosc, from what I've seen, there's nothing forbidding you to do that. So... you're a better golfer than me ^_^ \$\endgroup\$ – Rodolfo Dias Apr 21 '15 at 9:28
  • 1
    \$\begingroup\$ Ahem. Don't call Robert Fraser demented. codegolf.stackexchange.com/a/69360/43394 \$\endgroup\$ – wizzwizz4 Jan 16 '16 at 11:30
11
\$\begingroup\$

Any Roman numeral is a valid scene number

That means, that instead of:

Scene I
Scene II
Scene III
Scene IV
Scene V

You can do:

Scene L
Scene I
Scene C
Scene X
Scene V
\$\endgroup\$
  • \$\begingroup\$ is D a valid Roman numeral? IIRC, it's 500 (but I'm not sure if it's valid in SPL) \$\endgroup\$ – Giuseppe Sep 7 '17 at 15:33
  • \$\begingroup\$ @Giuseppe I don't understand why you don't just check that, but the official SPL interpreter supports M, C, D, X, L, I and V. \$\endgroup\$ – NieDzejkob Sep 7 '17 at 15:42
9
\$\begingroup\$

Remove unneeded words

Look at this (inserting newlines and whitespace for readability):

Puck:You is a big big cat!
     Open your heart!
Ajax:Be you worse than I?
     If so, let us return to Scene V!
     If not, you is a cat.
     You is the sum of I and the sum of a cat and you
     Speak thy mind!
     [Exeunt]

Looks pretty golfed eh? Here's an even more stripped down unintelligible form:

Puck:You big big cat!
     Open heart!
Ajax:Be you worse I?
     If so, let us Scene V!
     If not, you cat.
     You is the sum of I the sum of a cat you
     Speak mind!

For reference, here's a list of easily removable words from code:

  • Speak thy mind -> Speak thy
  • Open your heart -> Open heart *
  • Listen to thy heart -> Listen tothy
  • Open your mind -> Open mind *
  • You is a cat -> You cat *
    • Only applies to constants such as big cat, otherwise you still need the 'is'
  • Let us return to -> Let us
  • Be X [op] than Y? -> Be X [op] Y?
  • You is [op] of X and Y -> You is [op] ofX Y
  • [Exeunt] -> (removed entirely)

Legend:

  • X and Y are constants like cat, I or you
  • [op] are operations like nicer, the sum of
  • * means you can remove the punctuation if it's the last sentence of the play

If I come across any others I'll add it to the list.

For extra reference, here's the shortest header to start off a program:

,.Ajax,.Puck,.Act I:.Scene I:.[Enter Ajax and Puck]

Try it online!

Add Page and Ford as extra characters as necessary.

\$\endgroup\$
  • 1
    \$\begingroup\$ If you need even more characters, there's a list here \$\endgroup\$ – NieDzejkob May 9 '18 at 15:09
  • \$\begingroup\$ :| striped down \$\endgroup\$ – ASCII-only May 29 '18 at 5:59
6
\$\begingroup\$

Use short words

So here they are:

  • Use a instead of an or the, except the expressions the sum of and similar, since they won't work with a.
  • Use am, be or is instead of are or art.
  • Use I instead of me or myself.
  • Use you instead of thee, thou, thyself or yourself.
  • Use big for adjectives.
  • Use cat for positive numbers.
  • Use pig for negative numbers.
  • Use zero for zero.
  • Use worse for A < B (instead of smaller or punier).
  • Use nicer for A > B (instead of better, bigger, fresher, friendlier or jollier).
  • Character names:
    • 4 letters: Ajax, Ford, Page, Puck
    • 5 letters: Egeus, Helen, Julia, Lucio, Mopsa, Paris, Pinch, Priam, Regan, Robin, Romeo, Timon, Titus, Venus, Viola
    • 6 letters: Adonis, Aegeon, Alonso, Angelo, Arthur, Banquo, Bianca, Brutus, Cicero, Dorcas, Duncan, Emilia, Fenton, Hamlet, Hecate, Hector, Helena, Hermia, Imogen, Juliet, Lennox, Oberon, Olivia, Orsino, Portia, Thaisa, Thurio, Tybalt
    • 7 letters: Adriana, Aemilia, Agrippa, Antonio, Capulet, Cassius, Claudio, Dionyza, Escalus, Goneril, Horatio, Leonato, Luciana, Macbeth, Macduff, Malcolm, Mariana, Miranda, Octavia, Ophelia, Orlando, Othello, Pantino, Proteus, Publius, Shallow, Shylock, Slender, Solinus, Theseus, Titania, Troilus, Ulysses
    • 8 letters: Achilles, Beatrice, Benedick, Benvolio, Claudius, Cordelia, Cressida, Dogberry, Don John, Falstaff, Gertrude, Hermonie, Isabella, Lysander, Mercutio, Montague, Pericles, Polonius, Pompeius, Prospero, Rosalind, Stephano
    • 9 letters: Agamemnon, Antiochus, Autolycus, Balthazar, Brabantio, Cassandra, Cleopatra, Cornelius, Demetrius, Desdemona, Donalbain, Don Pedro, Ferdinand, Francisca, Hippolyta, King John, King Lear, Lychorida, Sebastian, The Ghost, Valentine, Vincentio
    • 10 letters: Andromache, Cymberline, Fortinbras, Friar John, King Henry
    • 11 letters: Mark Antony
    • 12 letters: Doctor Caius, King Richard, Lady Capulet, Lady Macbeth, Lady Macduff, Prince Henry, Queen Elinor
    • 13 letters: John of Gaunt, Julius Caesar, Lady Montague, Mistress Ford, Mistress Page
    • 14 letters: Friar Laurence, The Apothecary
    • 15 letters: Christopher Sly, Octavius Caesar
    • 17 letters: John of Lancaster, Mistress Overdone, The Duke of Milan
    • 18 letters: The Duke of Venice
    • 24 letters: The Abbot of Westminster
    • 28 letters: The Archbishop of Canterbury
    • If you really need more, you definitely should consider using the stack of each character.
\$\endgroup\$
  • \$\begingroup\$ Note that multi-word characters can omit any spaces after their name (from user202729's tip), so they are preferable to characters with only one word \$\endgroup\$ – Jo King May 29 '18 at 2:17
5
\$\begingroup\$

The "let us return to scene X" can be used even if the character being spoken to is off stage. So instead of:

Puck:Am I as fat as the sum of a big big big big big big cat and a cat?
Ajax:If not,let us return to scene III.
[Exit Puck]
[Enter Page]
Ajax:You is a big big big big big big cat.

You can do:

Puck:Am I as fat as the sum of a big big big big big big cat and a cat?
[Exit Puck]
[Enter Page]
Ajax:If not,let us return to scene III.You is a big big big big big big cat.
\$\endgroup\$
5
\$\begingroup\$

Remove redundant spaces

Apart from the trivial ones (two adjacent spaces, adjacent to a punctuation, adjacent to a newline, at the end) (with some exceptions), the space after the following tokens can be removed:

  • the sum of
  • let us
  • the ghost (like this) (but who would use this character anyway)
  • if so and if not (remove the , after this, and don't need to add any space. Example: if solet usact I)
  • listen to (so listen tothy works, like this)
  • and basically any multi-word tokens.

Note: This does not work with the Perl interpreter. It's probably just an unintended effect caused by Flex's parsing behavior. The "language standard" is not clear about that.

\$\endgroup\$
  • \$\begingroup\$ Time to back and edit some of my answers... Very nice find! \$\endgroup\$ – Jo King May 29 '18 at 2:15
  • \$\begingroup\$ Is that a bug in the tokenizer, or is that behavior defined in the language? \$\endgroup\$ – Cœur Sep 29 '18 at 4:36
  • 2
    \$\begingroup\$ @Cœur See update. \$\endgroup\$ – user202729 Sep 29 '18 at 7:33
5
\$\begingroup\$

You don't have to switch people in conditionals.

For example,

Ajax:Is you better than the sum of a fat fat fat fat cat and a fat cat?
Puck:If so,let us return to Scene I.

is longer than

Ajax:Is you better than the sum of a fat fat fat fat cat and a fat cat?If so,let us return to Scene I.
\$\endgroup\$
  • 1
    \$\begingroup\$ WHOOps. fixing. \$\endgroup\$ – Oliver Ni Sep 30 '18 at 3:53
4
\$\begingroup\$

Jumps can be shorter

You can use return to even if the scene is ahead, and vice versa. In fact, the interpreter doesn't even care if you omit it entirely. This means these three statements are 100% equivalent:

Let us proceed to Scene X.
Let us return to Scene X.
Let us Scene X.
\$\endgroup\$
3
\$\begingroup\$

Use shorter words

Examples:

Thy and thyself are shorter than your and yourself.

Is is shorter than are.

and more...

\$\endgroup\$
3
\$\begingroup\$

Use smart conditionals

For example, don't use

Ajax:Are you as good as or better than me?If so,let us return to Scene I.

But rather,

Ajax:Are you worse than me?If not,let us return to Scene I.
\$\endgroup\$
3
\$\begingroup\$

If (so|not) does not have to immediately follow the comparison.

Am I as big as you?You big big big big big cat.If so, you is the sum of you and a big big cat.
\$\endgroup\$
  • 4
    \$\begingroup\$ In fact, the results of a comparison are stored as a flag and can be used repeatedly across scene transitions or across several If sos. This can be helpful in avoiding repeating comparisons! \$\endgroup\$ – Jo King May 8 '18 at 12:04
3
\$\begingroup\$

Instead of substracting, add constants

You is the difference between I and a big cat.

is longer than

You is the sum of I and a big pig.
\$\endgroup\$
3
\$\begingroup\$

Use only one scene

Normally, you can't reuse the first scene of an act, since it always has [Enter Ajax and Puck] first thing. However, you can preface this with [Exeunt] to be able to reuse the first scene of a play. [Exeunt] is one byte shorter than declaring a new scene, and jumping to an Act is two bytes less than jumping to a Scene.

E.g: A simple cat program

,.Ajax,.Page,.Act I:.Scene I:.[Enter Page and Ajax]Scene V:.Ajax:Open mind!Speak thy!Let usScene V!

Try it online!

To:

,.Ajax,.Page,.Act I:.Scene I:.[Exeunt][Enter Page and Ajax]Ajax:Open mind!Speak thy!Let usAct I!

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Use constants to store large numbers

For example, if you have

Ajax:You is a fat fat fat fat fat fat fat fat fat fat cat!
Puck:You is the sum of thyself and a fat fat fat fat fat fat fat fat fat fat cat
Ajax:You is the sum of the difference of me and thyself and a fat fat fat fat fat fat fat fat fat fat cat!

You can just declare another person at the top

Ford,a fat fat fat fat fat fat fat fat fat fat cat.

and change your code to

Ajax:You is Ford.
Puck:You is the sum of thyself and Ford.
Ajax:You is the sum of the difference of me and thyself and Ford.
\$\endgroup\$
  • 7
    \$\begingroup\$ The official interpreter does not support declaring constants like that. \$\endgroup\$ – NieDzejkob Sep 7 '17 at 16:17
2
\$\begingroup\$

Gotos aren't the only commands usable with If (so|not)

Am I as big as you?If so,you is the sum of you and a big big cat.If not,you is the sum of you and twice I.
\$\endgroup\$
2
\$\begingroup\$

All newlines are ignored

,.Ajax,.Puck,.Page,.Act:.Scene:.[Enter Ajax and Puck]Ajax:You Puck.[Exeunt]
\$\endgroup\$
2
\$\begingroup\$

Use < or > instead of ==

Not applicable to every situation, but it's quite a bit shorter:

Puck == Ajax

Puck:Is I as bad as you?

Puck < Ajax or Puck > Ajax

Puck:Is I worse you?
Puck:Is I nicer you?

4 bytes shorter for both!

\$\endgroup\$
2
\$\begingroup\$

You don't need the ending . or !.

Try it online!

This can also be used before a [. (thanks jimmy23013)

,.Ajax,.Page,.Act I:.Scene I:.[Enter Ajax and Page]Ajax:You cat[Exeunt]

Examples:

  • ,.Ajax,.Page,.Act I:.Scene I:.[Enter Ajax and Page]Ajax:You cat
  • ,.Ajax,.Page,.Act I:.Scene I:.[Enter Ajax and Page]Ajax:Open mind[Exeunt]

Doesn't work in:

  • ,.Ajax,.Page,.Act I:.Scene I:[Enter Ajax] (right after Scene {number}:) (however this works, I don't know why)
  • ,.Ajax,.Page,.Act I:.Scene I:.[Enter Ajax and Page]Ajax:Listen to your heart (and shorter variants)
  • ,.Ajax,.Page,.Act I:.Scene I:.[Enter Ajax and Page]Ajax:Let us return to scene I (and shorter variants)
  • ,.Ajax,.Page,.Act I:.Scene I:.[Enter Ajax and Page]Ajax:Recall (only after empty Recall, Recall x or Recall@ etc. works)
  • ,.Ajax,.Page,.Act I:.Scene I:.[Enter Ajax and Page]Ajax:Speak thy (without mind)
\$\endgroup\$
  • \$\begingroup\$ This doesn't to work in some situations where you've already removed a word, such as Speak thy or Let us Scene I \$\endgroup\$ – Jo King May 29 '18 at 2:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.