Note: this answer is not meant to be a serious competitor
To Be or Not To Be, This is the Answer.
Hamlet, the main player in our story.
Horatio, Hamlet's guide through his internal struggles.
The Ghost, a handsome honest bold fair gentle king.
Claudius, the worthless usurper of the throne.
Ophelia, who Hamlet always writes two.
Polonius, the unfortunate third man caught between Hamlet and Claudius.
Brabantio, the greater.
Banquo, the lesser.
Emilia, the greater.
Egeus, the lesser.
Othello, the greater.
Orsino, the lesser.
Tybalt, the greater.
Titania, the lesser.
Valentine, who doubled is greater.
Viola, who doubled is lesser.
Act I: A simple question in so many words.
Scene I: Hamlet passes judgment over the cast.
[Enter Hamlet and Horatio]
Hamlet:
Thou art the sum of a good healthy sunny warrior and a lovely day.
[Exit Horatio]
[Enter Claudius]
Hamlet:
Thou art the sum of The Ghost and warm cute brave trustworthy hero.
[Exit Claudius]
[Enter Ophelia]
Hamlet:
Thou art the sum of Claudius and a smooth spaceman.
[Exit Ophelia]
[Enter Polonius]
Hamlet:
Thou art the sum of Ophelia and a plum.
[Exit Polonius]
[Enter Brabantio]
Hamlet:
Thou art the sum of The Ghost and the sum of The Ghost and a rich kingdom.
[Exit Brabantio]
[Enter Banquo]
Hamlet:
Thou art the sum of Brabantio and The Ghost.
[Exit Banquo]
[Enter Emilia]
Hamlet:
Thou art the sum of Brabantio and the sum of joy and a gentle girl.
[Exit Emilia]
[Enter Egeus]
Hamlet:
Thou art the sum of Emilia and The Ghost.
[Exit Egeus]
[Enter Othello]
Hamlet:
Thou art the sum of Emilia and the sum of a cunning lover and the sweetest golden embroidered rose.
[Exit Othello]
[Enter Orsino]
Hamlet:
Thou art the sum of Othello and The Ghost.
[Exit Orsino]
[Enter Tybalt]
Hamlet:
Thou art the sum of Othello and the sum of happiness and fair fine heaven.
[Exit Tybalt]
[Enter Titania]
Hamlet:
Thou art the sum of Tybalt and The Ghost.
[Exit Titania]
[Enter Valentine]
Hamlet:
Thou art the sum of Tybalt and the sum of a happy day and a pony.
[Exit Valentine]
[Enter Viola]
Hamlet:
Thou art the sum of Valentine and The Ghost.
[Exeunt]
Scene II: The beginning of Horatio's interrogation.
[Enter Hamlet and Horatio]
Hamlet:
Horatio:
Open your mind.
Art thou as good as Tybalt? If so, let us proceed to Scene IV.
Art thou as good as Titania? If so, let us proceed to Scene IV.
Art thou as good as Ophelia? If not, let us proceed to Scene XII.
Scene III: Are we to?
Horatio:
Open your mind.
Art thou as good as The Ghost? If so, let us proceed to Scene VII.
Let us proceed to Scene XII.
Scene IV: Can we go further than t?
Horatio:
Open your mind.
Art thou as good as Claudius? If so, let us proceed to Scene III.
Art thou as good as Valentine? If so, let us proceed to Scene VI.
Art thou as good as Viola? If so, let us proceed to Scene VI.
Art thou as good as Othello? If so, let us proceed to Scene V.
Art thou as good as Orsino? If not, let us proceed to Scene XII.
Scene V: Oone oor twoo?
Horatio:
Open your mind.
Art thou as good as The Ghost? If so, let us proceed to Scene VII.
Art thou as good as Othello? If so, let us proceed to Scene III.
Art thou as good as Orsino? If so, let us proceed to Scene III.
Let us proceed to Scene XII.
Scene VI: Hamlet desperately searches for whOo?.
Horatio:
Open your mind.
Art thou as good as Othello? If so, let us proceed to Scene III.
Art thou as good as Orsino? If so, let us proceed to Scene III.
Let us proceed to Scene XII.
Scene VII: Knowing to, what to do?
Horatio:
Open your mind.
Art thou as good as Brabantio? If so, let us proceed to Scene VIII.
Art thou as good as Banquo? If not, let us proceed to Scene XII.
Scene VIII: Learning what to Bleive.
Horatio:
Open your mind.
Art thou as good as me? If so, let us proceed to Scene XI.
Art thou as good as Emilia? If so, let us proceed to Scene X.
Art thou as good as Egeus? If so, let us proceed to Scene X.
Art thou as good as Polonius? If not, let us proceed to Scene XII.
Scene IX: The Eend is nigh?
Horatio:
Open your mind.
Art thou as good as me? If so, let us proceed to Scene XI.
Let us proceed to Scene XII.
Scene X: Wee may havee succeeeedeed.
Horatio:
Open your mind.
Art thou as good as Emilia? If so, let us proceed to Scene IX.
Art thou as good as Egeus? If so, let us proceed to Scene IX.
Art thou as good as me? If not, let us proceed to Scene XII.
Scene XI: Hamlet is at peace.
Horatio:
Thou art a beacon of happiness.
Let us proceed to Scene XIII
Scene XII: The demons have won.
Horatio:
Thou art nothing.
Scene XIII: Hamlet opens up.
Horatio:
Hamlet! Open your heart.
[Exeunt]
Outputs 0 if false, 1 if true.
This could easily be shorter (and if people really want me to, the word lengths could be cut down), but to do so would be a slap to the face of good ol' Will. I've always felt Horatio is the unsung hero of Hamlet, so I made sure that he was the one to deliver the intense monologue to Hamlet where Hamlet has to ultimately prove that he is as good as Horatio (who represents the newline).
The code itself is pretty simple. All of the characters sans Hamlet are ascii values (In order:newline,space,0,2,3,B,b,E,e,O,o,T,t,V,v
) and then the code is a simple state machine (specifically, a DFA) that transitions to Scene XI
as an accept state and Scene XII
as a reject state.
.
After making this, I just plugged it into Shakespeare, using the fact that I could drop down to the next state when they were numerically adjacent. I only tested it with the version of Shakespeare I linked in the title, but I believe we define a language by an implementation iirc.
Generally return values are considered valid if truthy or falsy.
– Draco18s no longer trusts SE – 2016-02-10T20:17:37.7835N0 l33t? “t0 b3” – manatwork – 2016-02-10T20:18:22.167
@Draco18s I had so many questions last time I posted a question I thought it best to make it very clear. – rybo111 – 2016-02-10T20:18:24.783
7Why does it have to be a function? – Dennis – 2016-02-10T20:19:32.017
2@rybo111 Well! That seems like they didn't understand the concept then ;) – Draco18s no longer trusts SE – 2016-02-10T20:19:34.503
@manatwork Good point, added. – rybo111 – 2016-02-10T20:19:53.170
@Dennis Edited. – rybo111 – 2016-02-10T20:29:43.717
Can we take one string as input, with one space between the args? – J Atkin – 2016-02-10T21:02:26.230
@FryAmTheEggman I think they whole thing should match one of those strings. – lirtosiast – 2016-02-10T21:05:19.340
@FryAmTheEggman The first and second values must both match one of the listed values.
not to
is not in the first list, so your example would be false. – rybo111 – 2016-02-10T21:12:14.210Why is
2
not in quotes? – J Atkin – 2016-02-10T21:38:40.677@JAtkin It's an integer example – rybo111 – 2016-02-10T21:50:58.133
Wait, we have to handle integers as input? (not a prob for my impl, but still a surprise) – J Atkin – 2016-02-10T21:52:51.197
13
This one begs for a Shakespeare solution. Non-competing of course, as the byte count would undoubtedly be huge...
– Darrel Hoffman – 2016-02-10T22:15:24.147@DarrelHoffman I imagine one of the creators would like to attempt that! – rybo111 – 2016-02-10T22:24:26.057
@rybo111 It appears some of the answers are failing to permit the first input to be either a string
'2'
or an integer2
. Maybe you should make that clearer in the challenge spec – Luis Mendo – 2016-02-10T22:25:09.6171@LuisMendo OK. Either is fine. Supporting both is not necessary. – rybo111 – 2016-02-10T22:26:43.933
That is the question indeed. – Zizouz212 – 2016-02-12T12:16:13.873