# To be or not to be

In the fewest bytes possible, determine whether the two values given each match one of the following:

First value

2      string or integer - whichever you prefer
to     case insensitive
too    case insensitive
two    case insensitive
t0     case insensitive (t zero)


Second value

b      case insensitive
be     case insensitive
bee    case insensitive
b3     case insensitive


# Examples

2          'Bee'            true
'2'        'b'              true
'not to'   'be'             false
'that is'  'the question'   false

• N0 l33t? “t0 b3” Commented Feb 10, 2016 at 20:18
• Why does it have to be a function? Commented Feb 10, 2016 at 20:19
• @rybo111 Well! That seems like they didn't understand the concept then ;) Commented Feb 10, 2016 at 20:19
• This one begs for a Shakespeare solution. Non-competing of course, as the byte count would undoubtedly be huge... Commented Feb 10, 2016 at 22:15
• @LuisMendo OK. Either is fine. Supporting both is not necessary. Commented Feb 10, 2016 at 22:26

# Shakespeare, 4778 Bytes

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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
[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.

• When I posted this question, I never envisaged I would get such a complex and yet very fitting answer! Commented Feb 12, 2016 at 12:16

# Retina, 28

• 1 byte saved thanks to @MartinBüttner.

Quite possibly my quickest ever code-golf answer - 9 minutes after OP.

Input parameters are comma-separated. Output is 1 for truthy and 0 for falsey.

i^(2|t[ow]?o|t0),b(e?e?|3)$ Try it online. • I always love it when fixing bugs saves bytes! – Neil Commented Feb 10, 2016 at 21:15 • @Neil yep - deleted code is debugged code :) Commented Feb 10, 2016 at 21:21 • @DigitalTrauma Truly, only sufficiently penitent code can be allowed in our brave new world. Commented Feb 10, 2016 at 21:24 # Pyth, 34 bytes .A}Lrw1c2c." Wô-WûÄæ­§Òé }  Try it online: Demonstration ### Explanation:  ."... packed string, gets decoded to: "2 TO TOO TWO T0 B BE BEE B3" c split by spaces c2 split into 2 lists: [['2', 'TO', 'TOO', 'TWO', 'T0'], ['B', 'BE', 'BEE', 'B3']] L for each list: w read a line r 1 convert it to uppercase } and test if it is part of this list list .A test if both return true  • Somehow if I remove the code before the packed string, the string becomes broken. Commented Feb 10, 2016 at 21:53 • @FryAmTheEggman I did. The output was "!$7C<Q/=/LF$VF4K:.-E" Commented Feb 10, 2016 at 21:55 • @FryAmTheEggman I tried a few times and compared the permalink, there was something missing. It seems it's because I copied and pasted, rather than using the link in the answer. I didn't know you'll miss some bytes when pasting packed strings into SE. Commented Feb 10, 2016 at 22:01 • @busukxuan Yeah I just noticed the same thing :P SE hides most unprintable characters unfortunately. Commented Feb 10, 2016 at 22:02 • This doesn't seem to pass the condition (t zero) for the first value Commented Feb 11, 2016 at 3:22 # Pyth, 41 bytes &xrw0c"2 to too two t0"dxrw0c"b be bee b3  Try it here! Straightforward list lookup. Prints an empty list as falsy value and a non-empty list as truthy value. Looking or a better way tho, I don't really like this one. # Oracle SQL 11.2, 86 bytes SELECT 1 FROM DUAL WHERE:1 IN('2','to','too','two','t0')AND:2 IN('b','be','bee','b3');  Returns one row for truthy and no row for falsey. # 05AB1E, 39 45 bytes Code: “2€„…«Œ† t0“' ¡)Ilrk\U“b€ïÍÝ b3“' ¡)Ilrk\>X>*  Try it online! Uses CP-1252 encoding. Truthy is when a number is outputted and falsy is when nothing is outputted. Non-competing version (39 bytes), works with the newest version: “2€„…«Œ† t0“ð¡)IlkU“b€ïÍÝ b3“ð¡)Ilk>X>*  ## ES6, 5648 45 bytes (...a)=>/^(2|t0|t[wo]?o),b(ee?|3)?$/i.test(a)


Saved 5 bytes thanks to @user81655. Saved 3 bytes from some further optimisation. Saved another 3 bytes thanks to @Patrick Roberts.

t[wo]?o is the shortest regex I could think of to match all three homophones.

If it's permitted to pass the two values as a single parameter array, then the rest parameter can become a normal parameter, saving another 5 bytes.

• @user81655 Not bad, but I've further improved it.
– Neil
Commented Feb 10, 2016 at 21:24
• if you use the rest parameter for input, it will save you 3 bytes: (...a)=>/^(2|t0|t[wo]?o),b(ee?|3)?$/.test(a) Commented Feb 10, 2016 at 22:33 • @PatrickRoberts Huh, I had thought about that, but I must have miscalculated, because I didn't think I was saving anything. – Neil Commented Feb 10, 2016 at 23:53 • The i flag is missing. Commented Feb 11, 2016 at 18:58 • @Florent Thanks for spotting that. (Maybe the examples should not be all lower case...) – Neil Commented Feb 11, 2016 at 19:31 # Perl 6, 45 44 bytes Thanks to the folks in IRC for helping me golf this down {@_~~(~2|/:i^t[0|oo?|wo]$/,/:i^b[ee?|3]?$/)}  usage > my &f = {@_~~(~2|/:i^t[0|oo?|wo]$/,/:i^b[ee?|3]?$/)} -> *@_ { #(Block|309960640) ... } > f("2", "Bee") True > f("2", "b") True > f("not to", "be") False > f("that is", "the question") False  Non-competing alternative, 54 bytes This is a nice alternative to the above if you think regexes are gross, but it is a tad longer. It could be golfed down a couple more bytes but since it's non-competing I'll leave it as is. {@_».lc~~(qw<to too two t0 2>.any,<b be bee b3>.any)}  • To anyone looking at this who doesn't know Perl 6. [ and ] denote a non-capturing group in a regex, which would be written as (?: and ) in Perl 5. To get a character class you have to place them in angle brackets <[ and ]>. Commented Feb 12, 2016 at 17:06 • b2gills++, I didn't even think to mention the differences in Perl 6 regexes Commented Feb 12, 2016 at 18:30 • I have had a downvote because someone didn't know that, so I always point it out. Commented Feb 12, 2016 at 18:33 • Is there a PP&CG rule stopping you from posting the more elegant golf as its own answer? I think a slightly longer* version would be worthy. *I hereby decree that elegant golf idioms include not caring about (not counting) whitespace. Commented Feb 13, 2016 at 19:27 ## Python 2.7, 133 bytes def e(a, b): c, d = """2,too,to,t0,two""","""be,b,bee,b3""" return a.lower() in c and b.lower() in d print e('2', 'bee')  Not sure if we're supposed to post solutions if there's a smaller version in the comments but here's my version in Python. Edit: Without the function it's only 73 bytes (and that's not even near the best answers. Forgive me I'm new a, b = "to", "bee" print a in "2 too to t0 two" and b in "be b bee b3"  • Welcome to PPCG! If you spent time writing and golfing an answer and didn't plagiarise (without attribution), then you're welcome to post your answer! Commented Feb 10, 2016 at 21:26 • Oh and most languages have a golfing-tips style question here. Python is no exception Commented Feb 10, 2016 at 21:30 • Note that this does work with input of 2 (integer) Commented Feb 10, 2016 at 21:36 • This returns True also for e('oo', '3') and similar substrings. Commented Feb 11, 2016 at 8:46 • @TheLateOne, Python isn't very golfable, so you will almost never beat the golfing languages like pyth or cjam, but getting in the 50, 60, or 70 range is pretty good for us on most challenges. Don't get discouraged! Commented Feb 11, 2016 at 14:47 ## Ruby, 5355 52 bytes f=->(a,b){/^(2|t[wo]?o|t0)$/i=~a&&/^b(e?e?|3)$/i=~b}  I'll be honest, this is my first attempt at trying to golf a problem. Function call in the form of f.call(firstValue, secondValue) 0 is Truthy, nil is Falsy. Test it Here # Japt, 36 bytes !Uv r"2|t(0|wo|oo?)" «Vv r"b(e?e?|3)  Maybe I missed something, but this should work completely. Test it online! ## Pyth, 39 bytes -3 bytes by @FryAmtheEggman .A.b}rN1cY\@Q,."0WÑ³5YYÅJB"."3EW´l¢ï  Try it here. • I'll fix it when I get to a computer. Commented Feb 10, 2016 at 21:30 # Python, 85 83 bytes @Manatwork saved me two bytes. This is pretty brute force, I'll look into regex solutions next. lambda a,b:a.lower()in'2 to too two t0'.split()and b.lower()in['b','be','bee','b3']  • For the first array: '2 to too two t0'.split() For the second array makes no difference. Commented Feb 11, 2016 at 11:54 • Damn, yes, I tried '2,to,too,two,t0'.split(','). Silly me. Commented Feb 11, 2016 at 11:54 ## PowerShell v3+, 74 70 bytes param($a,$b)+($a-in-split'2 to too two t0')*($b-in-split'b be bee b3')  Doesn't use regex. Takes two input, checks if the first one is -in the array that's been dynamically created by the -split operator, converts that Boolean to an int with +, then multiplies that * with checking whether the second is -in the second array (which will automatically cast the Boolean as an int). This works because x*y == x&y if x and y can only be 1 or 0. PowerShell by default is case-insensitive, so we get that for free. Will output 0 or 1 for falsey/truthy, respectively. Requires v3 or newer for the -in operator. Edit -- Saved 4 bytes by using unary -split # Groovy, 52 bytes f={x,y->"$x $y"==~"(?i)(2|t([wo]o?|0)) (b(ee?|3)?)"}  ==~ is a cool regex operator in groovy that checks for equality. Tests: Regex101 test. assert f('2', 'Bee') == true assert f('2', 'b') == true assert f('not to', 'be') == false assert f('that is', 'the question') == false  • What if x is t and y is 0b? – Neil Commented Feb 10, 2016 at 20:52 • What do you mean? Commented Feb 10, 2016 at 20:53 • I'd expect f('t', '0b') to be false, but I'm concerned that your code would return true. – Neil Commented Feb 10, 2016 at 20:58 • Ohhhh, Ok, I got it. Yep it would return the wrong thing. Commented Feb 10, 2016 at 21:01 # MATL, 32 4143 bytes jk'^(2|t[ow]?o|t0),b(e?e?|3)$'XX


Same approach as @DigitalTrauma's Retina answer. Inputs are separated by a comma. Truthy output is a string with the two inputs lowercased; falsy is no output.

Try it online!

j                                % input as a string
k                                % convert to lowercase
'^(2|t[ow]?o|t0),b(e?e?|3)$' % regular expression to match the two inputs XX % match regular expression  # C# 6, 132 bytes bool t(string x,string y)=>new[]{"2","to","too","two","t0"}.Contains(x.ToLower())&&new[]{"b","be","bee","b3"}.Contains(y.ToLower());  Ungolfed version (Only slightly more readable): bool t(string x, string y) => new[] { "2", "to", "too", "two", "t0" }.Contains(x.ToLower()) && new[] { "b", "be", "bee", "b3" }.Contains(y.ToLower());  # Python 2, 67 bytes Uses Digital Trauma's regex. Input is a single string separated by a comma. Not sure if that format is allowed for input... import re f=lambda x:bool(re.match('^(2|t[ow]?o|t0),b(e?e?|3)$',x))