29
\$\begingroup\$

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
\$\endgroup\$
18
  • 6
    \$\begingroup\$ N0 l33t? “t0 b3” \$\endgroup\$
    – manatwork
    Feb 10, 2016 at 20:18
  • 7
    \$\begingroup\$ Why does it have to be a function? \$\endgroup\$
    – Dennis
    Feb 10, 2016 at 20:19
  • 2
    \$\begingroup\$ @rybo111 Well! That seems like they didn't understand the concept then ;) \$\endgroup\$ Feb 10, 2016 at 20:19
  • 14
    \$\begingroup\$ This one begs for a Shakespeare solution. Non-competing of course, as the byte count would undoubtedly be huge... \$\endgroup\$ Feb 10, 2016 at 22:15
  • 1
    \$\begingroup\$ @LuisMendo OK. Either is fine. Supporting both is not necessary. \$\endgroup\$
    – rybo111
    Feb 10, 2016 at 22:26

18 Answers 18

34
\$\begingroup\$

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

This is the basic one I worked off of.

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.

\$\endgroup\$
1
  • 2
    \$\begingroup\$ When I posted this question, I never envisaged I would get such a complex and yet very fitting answer! \$\endgroup\$
    – rybo111
    Feb 12, 2016 at 12:16
18
\$\begingroup\$

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.

\$\endgroup\$
3
  • \$\begingroup\$ I always love it when fixing bugs saves bytes! \$\endgroup\$
    – Neil
    Feb 10, 2016 at 21:15
  • 6
    \$\begingroup\$ @Neil yep - deleted code is debugged code :) \$\endgroup\$ Feb 10, 2016 at 21:21
  • 1
    \$\begingroup\$ @DigitalTrauma Truly, only sufficiently penitent code can be allowed in our brave new world. \$\endgroup\$ Feb 10, 2016 at 21:24
7
\$\begingroup\$

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
\$\endgroup\$
6
  • \$\begingroup\$ Somehow if I remove the code before the packed string, the string becomes broken. \$\endgroup\$
    – busukxuan
    Feb 10, 2016 at 21:53
  • \$\begingroup\$ @FryAmTheEggman I did. The output was "!$7C<Q/=/LF$VF4K:.-E" \$\endgroup\$
    – busukxuan
    Feb 10, 2016 at 21:55
  • \$\begingroup\$ @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. \$\endgroup\$
    – busukxuan
    Feb 10, 2016 at 22:01
  • \$\begingroup\$ @busukxuan Yeah I just noticed the same thing :P SE hides most unprintable characters unfortunately. \$\endgroup\$ Feb 10, 2016 at 22:02
  • 1
    \$\begingroup\$ This doesn't seem to pass the condition (t zero) for the first value \$\endgroup\$ Feb 11, 2016 at 3:22
4
\$\begingroup\$

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.

\$\endgroup\$
0
4
\$\begingroup\$

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.

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

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>*
\$\endgroup\$
0
3
\$\begingroup\$

ES6, 56 48 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.

\$\endgroup\$
5
  • \$\begingroup\$ @user81655 Not bad, but I've further improved it. \$\endgroup\$
    – Neil
    Feb 10, 2016 at 21:24
  • 1
    \$\begingroup\$ 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) \$\endgroup\$ Feb 10, 2016 at 22:33
  • \$\begingroup\$ @PatrickRoberts Huh, I had thought about that, but I must have miscalculated, because I didn't think I was saving anything. \$\endgroup\$
    – Neil
    Feb 10, 2016 at 23:53
  • \$\begingroup\$ The i flag is missing. \$\endgroup\$
    – Florent
    Feb 11, 2016 at 18:58
  • \$\begingroup\$ @Florent Thanks for spotting that. (Maybe the examples should not be all lower case...) \$\endgroup\$
    – Neil
    Feb 11, 2016 at 19:31
3
\$\begingroup\$

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)}
\$\endgroup\$
4
  • 1
    \$\begingroup\$ 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 ]>. \$\endgroup\$ Feb 12, 2016 at 17:06
  • \$\begingroup\$ b2gills++, I didn't even think to mention the differences in Perl 6 regexes \$\endgroup\$
    – Hotkeys
    Feb 12, 2016 at 18:30
  • \$\begingroup\$ I have had a downvote because someone didn't know that, so I always point it out. \$\endgroup\$ Feb 12, 2016 at 18:33
  • \$\begingroup\$ 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. \$\endgroup\$
    – raiph
    Feb 13, 2016 at 19:27
3
\$\begingroup\$

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"
\$\endgroup\$
9
  • 2
    \$\begingroup\$ 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! \$\endgroup\$ Feb 10, 2016 at 21:26
  • \$\begingroup\$ Oh and most languages have a golfing-tips style question here. Python is no exception \$\endgroup\$ Feb 10, 2016 at 21:30
  • \$\begingroup\$ Note that this does work with input of 2 (integer) \$\endgroup\$
    – wnnmaw
    Feb 10, 2016 at 21:36
  • 3
    \$\begingroup\$ This returns True also for e('oo', '3') and similar substrings. \$\endgroup\$
    – manatwork
    Feb 11, 2016 at 8:46
  • 1
    \$\begingroup\$ @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! \$\endgroup\$
    – wnnmaw
    Feb 11, 2016 at 14:47
2
\$\begingroup\$

Ruby, 53 55 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

\$\endgroup\$
1
\$\begingroup\$

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!

\$\endgroup\$
1
\$\begingroup\$

Pyth, 39 bytes

-3 bytes by @FryAmtheEggman

.A.b}rN1cY\@Q,."0Wѳ5YYÅJB"."3EW´l¢ï

Try it here.

\$\endgroup\$
1
  • \$\begingroup\$ I'll fix it when I get to a computer. \$\endgroup\$
    – lirtosiast
    Feb 10, 2016 at 21:30
1
\$\begingroup\$

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']
\$\endgroup\$
2
  • 1
    \$\begingroup\$ For the first array: '2 to too two t0'.split() For the second array makes no difference. \$\endgroup\$
    – manatwork
    Feb 11, 2016 at 11:54
  • \$\begingroup\$ Damn, yes, I tried '2,to,too,two,t0'.split(','). Silly me. \$\endgroup\$
    – Ogaday
    Feb 11, 2016 at 11:54
1
\$\begingroup\$

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

\$\endgroup\$
0
\$\begingroup\$

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
\$\endgroup\$
4
  • \$\begingroup\$ What if x is t and y is 0b? \$\endgroup\$
    – Neil
    Feb 10, 2016 at 20:52
  • \$\begingroup\$ What do you mean? \$\endgroup\$
    – J Atkin
    Feb 10, 2016 at 20:53
  • \$\begingroup\$ I'd expect f('t', '0b') to be false, but I'm concerned that your code would return true. \$\endgroup\$
    – Neil
    Feb 10, 2016 at 20:58
  • \$\begingroup\$ Ohhhh, Ok, I got it. Yep it would return the wrong thing. \$\endgroup\$
    – J Atkin
    Feb 10, 2016 at 21:01
0
\$\begingroup\$

MATL, 32 41 43 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
\$\endgroup\$
0
\$\begingroup\$

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());
\$\endgroup\$
0
\$\begingroup\$

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))
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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