45
\$\begingroup\$

Recently, an electrical engineer studying traffic light timings was fined $500 by the state of Oregon for referring to himself as an engineer.

Given a 2 letter string as input, representing a US state, output:

  • I am not an engineer if the state is Oregon (OR)
  • I am an engineer if the state is any other US state
  • What is an engineer? given any other input

Output may not contain any leading whitespace, but may contain as much trailing whitespace as you wish.

You can assume the input will always be 2 uppercase letters.

Here is a list of all 50 US state abbreviations:

AL, AK, AZ, AR, CA, CO, CT, DE, FL, GA, HI, ID, IL, IN, IA, KS, KY, LA, ME,
MD, MA, MI, MN, MS, MO, MT, NE, NV, NH, NJ, NM, NY, NC, ND, OH, OK, OR, PA,
RI, SC, SD, TN, TX, UT, VT, VA, WA, WV, WI, WY

Scoring

This is , so fewest bytes in each language wins!

\$\endgroup\$
4
  • \$\begingroup\$ Can I have a trailing space in the output? \$\endgroup\$ Commented Jun 2, 2017 at 13:51
  • \$\begingroup\$ @BusinessCat yes, will update spec to say that \$\endgroup\$
    – Mayube
    Commented Jun 2, 2017 at 14:06
  • 4
    \$\begingroup\$ Side note: If you concatenate the whole string together, you get "...OKORPARISCSDTN..." ;-) \$\endgroup\$ Commented Jun 4, 2017 at 6:42
  • \$\begingroup\$ Mats Järlström wouldn't be allowed to present himself as an engineer in Texas, either. \$\endgroup\$
    – Ben Voigt
    Commented Jun 5, 2017 at 17:22

38 Answers 38

17
\$\begingroup\$

C#, 311 309 240 237 222 195 184 183 bytes

s=>s=="OR"?"I am not an engineer":"MINCALA MSCTNMNVAKY WAZ PAR FL GA NHID COKSD ME MDE MA MTX NE NJ NY ND MOH RIA UT WVT WIL WY".Contains(s)?"I am an engineer":"What is an engineer?";

Try it online!

Saved 2 bytes by adding the space before an to b

-69 (huehue) -72 bytes thanks to TheLethalCoder

-15 bytes thanks to TotallyHuman's genius states string

-38 bytes cos more string compression

Ungolfed:

public static string a(string s)
{
    var b = " an engineer";
    if (s == "OR")
    {
        return "I am not" + b;
    }
    else
    {
        if ("MINCALA MSCTNMNVAKY WAZ PAR FL GA NHID COKSD ME MDE MA MTX NE NJ NY ND MOH RIA UT WVT WIL WY".Contains(s))
        {
            return "I am" + b;
        }
        else
        {
            return $"What is{b}?";
        }
    }
}
\$\endgroup\$
10
  • \$\begingroup\$ Use ..."+b instead of interpolated strings, change if..else if...else to return s=="OR"?....:System.Arr...` i.e. use a ternary. Use u.Contains instead of Array.Exists. I think if you use spaces instead of commas then .Split() with no params will work. \$\endgroup\$ Commented Jun 2, 2017 at 10:28
  • \$\begingroup\$ declare b and u in the same line and even though you have to use explicit type string should still save you a byte \$\endgroup\$
    – LiefdeWen
    Commented Jun 2, 2017 at 10:31
  • \$\begingroup\$ @StefanDelport u is an array not string. However, you can save bytes by setting u as a string and using .Contains on it. \$\endgroup\$ Commented Jun 2, 2017 at 10:35
  • \$\begingroup\$ 240 bytes: s=>{var b=" an engineer";return s=="OR"?"I am not"+b:"AL AK AZ AR CA CO CT DE FL GA HI ID IL IN IA KS KY LA ME MD MA MI MN MS MO MT NE NV NH NJ NM NY NC ND OH OK PA RI SC SD TN TX UT VT VA WA WV WI WY".Contains(s)?"I am"+b:$"What is{b}?";};. Think I've removed all the relevant whitespace. (Untested) \$\endgroup\$ Commented Jun 2, 2017 at 10:38
  • 1
    \$\begingroup\$ You can golf this by defining " an engineer" as a separate variable to save some bytes. \$\endgroup\$
    – AAM111
    Commented Jun 2, 2017 at 23:29
11
\$\begingroup\$

JavaScript (ES6), 182 bytes

s=>['I am'+(x=' an engineer'),`What is${x}?`,'I am not'+x][s=='OR'?2:'MNNMLATNAKALARAZCACOCTDEFLGAHIIAIDILINKSKYMAMDMEMIMOMSMTNCNDNENHNJNVNYOHOKPARISCSDTXUTVAVTWAWIWVWY'.search(s)&1]

Demo

let f =

s=>['I am'+(x=' an engineer'),`What is${x}?`,'I am not'+x][s=='OR'?2:'MNNMLATNAKALARAZCACOCTDEFLGAHIIAIDILINKSKYMAMDMEMIMOMSMTNCNDNENHNJNVNYOHOKPARISCSDTXUTVAVTWAWIWVWY'.search(s)&1]

console.log(f("OR"))
console.log(f("NY"))
console.log(f("TX"))
console.log(f("YO"))

\$\endgroup\$
4
  • 3
    \$\begingroup\$ Fails for e.g. LA :/ \$\endgroup\$
    – Christoph
    Commented Jun 2, 2017 at 13:07
  • \$\begingroup\$ @Christoph Should be OK now. Thanks for reporting this! \$\endgroup\$
    – Arnauld
    Commented Jun 2, 2017 at 13:14
  • \$\begingroup\$ Thought it was missing OR for moment - silly! \$\endgroup\$
    – Chas Brown
    Commented Jun 3, 2017 at 2:33
  • \$\begingroup\$ Use codegolf.stackexchange.com/a/124164/76323 to optimize \$\endgroup\$
    – l4m2
    Commented Mar 9, 2018 at 6:19
8
\$\begingroup\$

C, 215 208 190 bytes

-7 thanks to Cool Guy

#define z" an engineer"
#define f(s)!strcmp(s,"OR")?"I am not"z:strstr("MINCALA MSCTNMNVAKY WAZ PAR FL GA NHID COKSD ME MDE MA MTX NE NJ NY ND MOH RIA UT WVT WIL WY",s)?"I am"z:"What is"z"?"

Used @totallyhuman's "genus string".

How it works:

  • "string"z automatically concatenates "string" with z (" an engineer"). Yes, C does that.
  • !strcmp(s,"OR") compares the string against "OR".
  • ?"I am not"z returns "I am not an engineer" if true. Otherwise...
  • :strstr(...,s) checks if @totallyhuman's genius string contains the provided string.
  • ?"I am"z returns "I am an engineer" if so, and...
  • :"What is"z"?") returns "What is an engineer?" otherwise.

Try it online!

\$\endgroup\$
4
  • 1
    \$\begingroup\$ 206 bytes: #define z " an engineer" f(char*s){!strcmp(s,"OR")?puts("I am not"z):strstr("MINCALA MSCTNMNVAKY WAZ PAR FL GA NHID COKSD ME MDE MA MTX NE NJ NY ND MOH RIA UT WVT WIL WY",s)?puts("I am"z):puts("What is"z);} \$\endgroup\$
    – Spikatrix
    Commented Jun 3, 2017 at 9:31
  • \$\begingroup\$ @CoolGuy That won't work for "What is an engineer?" But I got it to work in 209 bytes. Thanks! \$\endgroup\$
    – MD XF
    Commented Jun 3, 2017 at 16:49
  • \$\begingroup\$ You can return the string instead of printing it \$\endgroup\$
    – l4m2
    Commented Mar 9, 2018 at 16:03
  • \$\begingroup\$ @l4m2 Did something similar. \$\endgroup\$
    – MD XF
    Commented Mar 11, 2018 at 18:23
6
\$\begingroup\$

Python 2, 228 168 bytes

lambda s:('What is%s?','I am'+' not'*(s=='OR')+'%s')[s in'MINCALA MSCTNMNVAKY WAZ PAR FL GA NHID COKSD ME MDE MA MTX NE NJ NY ND MOH ORIA UT WVT WIL WY']%' an engineer'

Try it online!

\$\endgroup\$
1
  • 2
    \$\begingroup\$ The state encoding is hilarious. \$\endgroup\$
    – Ramon Snir
    Commented Jun 2, 2017 at 16:50
5
\$\begingroup\$

Python 2, 192 186 182 178 176 bytes

Could probably compress the state string more.

lambda s,e=' an engineer':'I am'+' not'*(s=='OR')+e if s in'MINCALAZ SCT FL GA WIAKSD ME MD MA MNMS MOKY MTNE NVTX NH NJ NY ND COHIDE OR PARIL UT VA WA WV WY'else'What is%s?'%e

Try it online!

\$\endgroup\$
8
  • 2
    \$\begingroup\$ You only use u in if s in u can you note use it directly instead of declaring it? \$\endgroup\$ Commented Jun 2, 2017 at 11:20
  • 1
    \$\begingroup\$ @totallyhuman that string compression is pretty amazing, nice one! \$\endgroup\$
    – Mayube
    Commented Jun 2, 2017 at 11:23
  • 2
    \$\begingroup\$ @totallyhuman VALA WAZ NCA COH CTX SDE FL GA HID WIL MIN IAKSC KY ME MD MA MNMS MOK MTNE NH NJ NY ND PARI UT NVT WV WY is the smallest I can make it \$\endgroup\$
    – Mayube
    Commented Jun 2, 2017 at 11:27
  • 2
    \$\begingroup\$ 'MINCALA MSCTNMNVAKY WAZ PAR FL GA NHID COKSD ME MDE MA MTX NE NJ NY ND MOH ORIA UT WVT WIL WY' \$\endgroup\$ Commented Jun 2, 2017 at 11:29
  • 2
    \$\begingroup\$ Whoops, sorry it took me so long. Seems I have lost as copying that string doesn't make my answer better than the one using it. Please stop upvoting this and upvote the other better answer. \$\endgroup\$ Commented Jun 2, 2017 at 12:49
5
\$\begingroup\$

Java (JDK 10), 184 bytes

s->s.format(s.equals("OR")?"I am not%s":"MINCALA MSCTNMNVAKY WAZ PAR FL GA NHID COKSD ME MDE MA MTX NE NJ NY ND MOH RIA UT WVT WIL WY".contains(s)?"I am%s":"What is%s?"," an engineer")

Try it online!

I apologize for reusing the compressed string: I couldn't find anything better by myself... :(

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

05AB1E, 104 103 101 bytes

„€À€ˆ„I€Ü‚.•~Zµ∞/'—¶[@øl•Œ2ù.•9₆\|&׃Ω#àöF},cΓ páe;ð²∍₆jÌn#dÅ?DvĆ8A•2ôìuIå©è¹„ORQi'€–}„€¤©É)ðýª'?®_×J

Try it online!

Old 104 byte version in case that is more easily improved.

„€À€ˆ„I€Ü‚.•ÂkXñ…ΓVt€Ïè∍‡Λi„2¶’að=–½6™oÑþÁāõgO·ð~
λ†₃›;â&ÄFv¾‡1~ǝQa«;cS•u2ôIå©è¹„ORQi'€–}„€¤©É)ðýª'?®_×J

Not happy with the compression nor the special case for ?.

\$\endgroup\$
3
  • \$\begingroup\$ OK what is this? Did you just re-order the states or something? \$\endgroup\$ Commented Jun 2, 2017 at 12:05
  • \$\begingroup\$ @EriktheOutgolfer: The 104 byte version is just a compression of the numbers corresponding to the characters positions in the alphabet (A=1,C=3 ...). The 103 byte version does the same for some states and merge some states that end in the same letter that a new state starts with. I'm sure this can still be improved and I'll add a better explanation when I've golfed it more. \$\endgroup\$
    – Emigna
    Commented Jun 2, 2017 at 12:12
  • 1
    \$\begingroup\$ Nice answer! I like the .•~Zµ∞/'—¶[@øl•Œ2ù you've used for some of the states, instead of just compressing all the states and doing the . And nice approach overall. (Glad I saw your answer before attempting something myself, because it definitely wouldn't have been as short..) \$\endgroup\$ Commented Sep 17, 2018 at 14:35
4
\$\begingroup\$

R, 109 96 bytes

function(x)sub("#"," an engineer",c("I am not#","I am#","What is#?"))[2-x%in%state.abb+!x=="OR"]

Try it online!

13 bytes thanks to J.Doe - through use of regex and indexation.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ 97 bytes \$\endgroup\$
    – J.Doe
    Commented Sep 17, 2018 at 15:01
  • 1
    \$\begingroup\$ @J.Doe sub is much better, thank you! \$\endgroup\$
    – JayCe
    Commented Sep 17, 2018 at 16:54
  • \$\begingroup\$ 96 bytes 😉 \$\endgroup\$
    – J.Doe
    Commented Sep 18, 2018 at 13:47
  • \$\begingroup\$ @J.Doe Of course! \$\endgroup\$
    – JayCe
    Commented Sep 18, 2018 at 15:34
4
\$\begingroup\$

F#, 222 211 bytes

let f v=let(a,b)=if"OR"=v then("I am not",".")elif"WALAKSCARINMNVTNCTX NHIDE MOHIL COKY MSD PAZ WIA WVA FL GA MA MD ME MI MT NE ND NJ NY UT WY".Contains v then("I am",".")else("What is","?")in a+" an engineer"+b

Try it online!

Expanded:

let f v =
    let (a,b) =
        if "OR" = v then ("I am not",".")
        elif "WALAKSCARINMNVTNCTX NHIDE MOHIL COKY MSD PAZ WIA WVA FL GA MA MD ME MI MT NE ND NJ NY UT WY".Contains v then ("I am",".")
        else ("What is","?")
    a + " an engineer" + b

Given a two-letter state v passed to the function f, build a tuple (a, b) representing the head and tail of the "engineer" sentence.

Feel free to use the "compressed state string" freely; it's one whole byte shorter than the MINCALA one...

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

CJam, 143 bytes

"ORIA MINCALA MSCTNMNVAKY WAZ PAR FL GA NHID COKSD ME MDE MA MTX NE NJ NY ND MOH UT WVT WIL WY"q#g"I am not 
I am 
What is?"N/=)" an engineer"\

Try it online! or as a test suite

Explanation

"ORIA...."       e# Push a string in which every state is a substring, but no non-state is
                 e# a substring.
q                e# Read the input.
#                e# Find the index of the input in the string. (-1 if not found)
g                e# Signum of the index: -1 for negative, 0 for 0, 1 for positive.
"I am.... "      e# Push this string. Note the trailing space on the first two lines of it.
N/               e# Split it on newlines.
=                e# Get the string at index given by the signum.
)                e# Pull out the last character.
" an engineer"\  e# Push " an engineer" and bring the other character to the TOS.
                 e# Implicit output.

Since Oregon (OR) is at the start of the string, finding the signum of the index of the input in that will be -1 if not found, 0 if OR, 1 if any other state. Which string to print can be decided by that.

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

Japt, 136 135 131 129 128 bytes

More savings may be available by experimenting with the order of the state abbreviations - I'll come back to that in a while.

`mnnmlãGLÏz¯¬ct¸flgaá[9¨kyµmçpCijmsmtnhnvnyn¬kpÂÉcsdk¡x©vavt°±wvwy`ò øUv)?"I am {¥"OR"?"not ":P}"+` à¨\ `:`Wt   à¨\?

Try it online


Explanation

  • We take a compressed string of the lowercased abbreviations, decompress it, and split it into an array of 2 character strings using the ò method.
  • We then use the ø method to see if the array contains Uv, which is the input string converted to lowercase.
  • If we so, we build our output string, beginning with "I am "
  • Checking if the input string ¥ (is equal to) "OR" allows us to append either "not " or the empty string variable P.
  • And then we decompress and append the compressed string "an engineer".
  • If the input was not found in the array, then we output the decompression of compressed string "What is an engineer?".
\$\endgroup\$
3
\$\begingroup\$

Python 3, 180 179 178 bytes

def f(s):e=" not"*(s=="OR")+" an engineer";return"I am"+e if s in"PALAKSCAZ CTNMINCOR FL GA MDE ME MND MA MSD MOKY NE NH NJ NY WA OHID UTX MTNVARIA WIL WVT WY"else"What is"+e+"?"

Try it online!

\$\endgroup\$
3
  • \$\begingroup\$ Yep, it's correct: Try it online! \$\endgroup\$ Commented Sep 17, 2018 at 15:32
  • \$\begingroup\$ 166 bytes. I'm sure the string can also be tightened up a liitle more by reusing states \$\endgroup\$
    – Jo King
    Commented Sep 17, 2018 at 22:53
  • \$\begingroup\$ Thanks @JoKing. It resembles the Python 2 answer too much at this point IMO :). I've been trying to compress the string, but the shortest I could get was 92 symbols. I've written a short script to do that, but it can only cut it down to 94 characters, and it doesn't compress optimally. I also think that in this particular challenge the magic string itself should not be included in the byte count. \$\endgroup\$ Commented Sep 18, 2018 at 18:50
2
\$\begingroup\$

PHP, 188 Bytes

$e=" an engineer";echo strpos(_TNNMLAALAKAZARCACOCTDEFLGAHIIDILINIAKSKYMEMDMAMIMNMSMOMTNENVNHNJNYNCNDOHOKORPARISCSDTXUTVTVAWAWVWIWY,$argn)&1?"I am".($argn!="OR"?"":" not").$e:"What is$e?";

Try it online!

\$\endgroup\$
5
  • \$\begingroup\$ in_array(...) to strpos(_AKALARAZCACOCTDEFLGAHIIAIDILINKSKYLAMAMDMEMIMNMOMSMTNCNDNENHNJNMNVNYOHOKPARISCSDTNTXUTVAVTWAWIWVWY,$argn)&1. \$\endgroup\$
    – Christoph
    Commented Jun 2, 2017 at 12:54
  • \$\begingroup\$ @Christoph works not for an Input for example of LA \$\endgroup\$ Commented Jun 2, 2017 at 13:03
  • \$\begingroup\$ Hm right :/ maybe we can reorder the string a bit .. I'll try. Also invalidates the js answer btw. \$\endgroup\$
    – Christoph
    Commented Jun 2, 2017 at 13:08
  • \$\begingroup\$ _NMMNINTNRIHIMIWISCNCCTMTUTVTWVNVFLILCAALGAIAMAPAVAWACOLAMOAKARKSMSNHOHOKORAZDEIDKYMEMDNENJNYNDSDTXWY works \$\endgroup\$
    – Christoph
    Commented Jun 2, 2017 at 13:24
  • \$\begingroup\$ @Christoph Or my order work too. \$\endgroup\$ Commented Jun 2, 2017 at 14:40
2
\$\begingroup\$

C#, 178 bytes

s=>(s=="OR"?"I am notx":"MINCALA MSCTNMNVAKY WAZ PARIA FL GA NHID COKSD ME MDE MA MTX NE NJ NY ND MOH UT WVT WIL WY".Contains(s)?"I amx":"What isx?").Replace("x"," an engineer");

Run in C# Pad

Golf based on Mayube's solution; new here, so I don't have enough rep to comment.

\$\endgroup\$
2
  • \$\begingroup\$ Might want to edit in a link in to his solution :) If you click share on his solution, it gives you a link straight to it. \$\endgroup\$
    – Stephen
    Commented Jun 2, 2017 at 20:26
  • \$\begingroup\$ @StephenS Thanks for the tip! \$\endgroup\$ Commented Jun 2, 2017 at 20:27
2
\$\begingroup\$

Haskell, 220 214 210 209 bytes

s(a:b:c)=[a,b]:s(b:c)
s _=[]
a="I am "
e="an engineer "
i"OR"=a++"not "++e
i x|x`elem`s"MINCALA MSCTNMNVAKY WAZ PAR FL GA NHID COKSD ME MDE MA MTX NE NJ NY ND MOH RIA UT WVT WIL WY"=a++e
i _="What is "++e++"?"

Try it online!

\$\endgroup\$
5
  • \$\begingroup\$ otherwise = True, 1<2 is even shorter \$\endgroup\$
    – BlackCap
    Commented Jun 2, 2017 at 14:45
  • \$\begingroup\$ Facepalm, thanks! \$\endgroup\$
    – bartavelle
    Commented Jun 2, 2017 at 14:51
  • \$\begingroup\$ You have included OR in the long string in the second definition of i \$\endgroup\$
    – BlackCap
    Commented Jun 2, 2017 at 15:02
  • \$\begingroup\$ I stole the long string from the other answers. OR isn't part of it though? \$\endgroup\$
    – bartavelle
    Commented Jun 2, 2017 at 16:26
  • 1
    \$\begingroup\$ No, not anymore :) \$\endgroup\$
    – BlackCap
    Commented Jun 2, 2017 at 16:28
1
\$\begingroup\$

Javascript 204

s=>{h=/^(A[LKZR]|C[AOT]|DE|FL|[GPLV]A|[HR]I|I[DLNA]|K[SY]|M[EDAINSOT]|N[EVHJMYCD]|O[HK]|S[CD]|T[NX]|[VU]T|W[AVIY]|(OR))$/.exec(s);return(!h?"What is ":"I am "+(h[2]?"not ":""))+"an engineer"+(!h?'?':'')}
\$\endgroup\$
2
  • 1
    \$\begingroup\$ Pure optimize s=>(!(h=/(A[LKZR]|C[AOT]|DE|FL|[GPLV]A|[HR]I|I[DLNA]|K[SY]|M[EDAINSOT]|N[EVHJMYCD]|O[HKR]|S[CD]|T[NX]|[VU]T|W[AVIY])/.test(s))?"What is":"I am"+(s=='OR'?" not":""))+" an engineer"+['?'[+h]] \$\endgroup\$
    – l4m2
    Commented Mar 9, 2018 at 6:15
  • \$\begingroup\$ @l4m2 nice, that's got my answer beat. \$\endgroup\$
    – martin
    Commented Mar 9, 2018 at 6:27
1
\$\begingroup\$

AWK, 189 bytes

/A[LKZR]|C[AOT]|DE|FL|[GPV]A|HI|I[DLNA]|KS|KY|LA|M[EDAINSOT]|N[EVHJMYCD]|O[HKR]|RI|SC|SD|TN|TX|UT|VT|W[AVIY]/{print"I am "($0~OR?"not ":"")"an engineer";exit}
{print"What is an engineer?"}

If input matches a regex containing all the state abbreviations, print "I am an engineer" with a 'not' inserted in the middle if the state is Oregon, then exit.

If the input does not match the regex, it must not be a US state abbreviation.

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

Python 3, 238 bytes

def f(x):s=x in('ALAKAZARCACOCTDEFLGAHIIDILINIAKSKYLAMEMDMAMIMNMSMOMTNENVNHNJNMNYNCNDOHOKORPARISCSDTNTXUTVTVAWAWVWIWY'[i:i+2]for i in range(0,100,2));o=x=='OR';q=(1-o)*(1-s);return q*'What is'+(1-q)*('I am'+o*' not')+' an engineer'+q*'?'

Explanation

No compression techniques used.

def f(x):
    # Check if State
    s = x in ('ALAK...WIWY'[i:i+2]
              for i in range(0, 100, 2))

    # Check if Oregon
    o = x == 'OR'

    # Check if neither Oregon nor State
    q = (1-o) * (1-s)

    # Construct output string
    return q * 'What is' + \
        (1-q) * ('I am' + o * ' not') + \
        ' an engineer' + \
        q * '?'
\$\endgroup\$
2
  • \$\begingroup\$ It's Oregon, not Ohio. \$\endgroup\$
    – L3viathan
    Commented Jun 4, 2017 at 9:24
  • 1
    \$\begingroup\$ @L3viathan Not sure how I mess that up after seeing Oregon everywhere due to Life is Strange... ¯\_(ツ)_/¯ \$\endgroup\$ Commented Jun 4, 2017 at 9:43
1
\$\begingroup\$

Java, 173 bytes

s->(!"MINCALARIA MSCTNMNVAKY WAZ PAR FL GA NHID COKSD ME MDE MA MTX NE NJ NY ND MOH UT WVT WIL WY OR".contains(s)?"What is":"I am"+(s.equals("OR")?" not":""))+" an engineer"
\$\endgroup\$
1
  • 3
    \$\begingroup\$ Welcome to PPCG! All entries must be a full program or a function; I believe you can turn this into a valid lambda expression (and therefore function) by adding s-> to the beginning. \$\endgroup\$ Commented Jun 2, 2017 at 23:01
1
\$\begingroup\$

Stax, 100 bytes

This language postdates the challenge. But the author (me) didn't see it until now.

éë&W≈#W¬π█▐╜╣╟◙√a☻∞ZrπU♫ÿô♠▌⌠Që≡AûpI⌡ÄNA綵↑╝╣òøΩ.¬É]╩Æ↓d∩é¡2ŲeB┼¼▬5∟┤sW♠♂↑q▐WMï╝|Ñ↑╫+3¼↔îûvlLΩ∟┬oë

Run and debug it

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

JavaScript ES6, 175171 Bytes

x=>[`What is${e=" an engineer"}?`,`I am${x=="OR"?" not"+e:e}`][+!!'MINCALA MSCTNMNVAKY WAZ PAR FL GA NHID COKSD ME MDE MA MTX NE NJ NY ND MOH ORIA UT WVT WIL WY'.match(x)]

Joined lots of good

Or 152 bytes on ISO encoding

Generator:

'x=>[`What is${e=" an engineer"}?`,`I am${x=="OR"?" not"+e:e}`][+!!btoa`*`.match(x)]'.replace('*',atob('MINCALA MSCTNMNVAKY WAZ PAR FL GA NHID COKSD ME MDE MA MTX NE NJ NY ND MOH ORIA UT WVT WIL WY '.replace(/ /g,'/')))
\$\endgroup\$
1
  • \$\begingroup\$ It might be possible to rearrange the string so using btoa to expand \$\endgroup\$
    – l4m2
    Commented Mar 9, 2018 at 15:50
1
\$\begingroup\$

C (gcc), 0+176 bytes

-Dz"=an engineer" -Df(s)*s-79|1[s]-82?strstr("MINCALA=MSCTNMNVAKY WAZ PAR FL GA NHID COKSD ME MDE MA MTX NE NJ NY ND MOH RIA UT WVT WIL WY",s)?"I am"z:"What is"z"?":"I am not"z

Try it online!

pure translate

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

Powershell, 175 bytes

(('I am'+' not'*!($i='ORIA MINCALA MSCTNMNVAKY WAZ PAR FL GA NHID COKSD ME MDE MA MTX NE NJ NY ND MOH UT WVT WIL WY'.IndexOf($args))+($e=' an engineer')),"What is$e`?")[!++$i]

Test script:

$f = {

$e=' an engineer'
$i='ORIA MINCALA MSCTNMNVAKY WAZ PAR FL GA NHID COKSD ME MDE MA MTX NE NJ NY ND MOH UT WVT WIL WY'.IndexOf($args)
(('I am'+' not'*!$i+$e),"What is$e`?")[!++$i]

# Important! OR is a first state in the modified @totallyhuman's genuis string

}

@(
    ,('OR', 'I am not an engineer')
    ,('AL', 'I am an engineer')
    ,('IL', 'I am an engineer')
    ,('ZZ', 'What is an engineer?')
) | % {
    $s,$e = $_
    $r = &$f $s
    "$($r-eq$e): $r"
}

Output:

True: I am not an engineer
True: I am an engineer
True: I am an engineer
True: What is an engineer?
\$\endgroup\$
0
\$\begingroup\$

Python 3, 236 182 181 bytes

lambda s:'I am not'+e if s=='OR'else'I am'+e if s in'MINCALA MSCTNMNVAKY WAZ PAR FL GA NHID COKSD ME MDE MA MTX NE NJ NY ND MOH RIA UT WVT WIL WY'else'What is%s?'%e
e=' an engineer'

Try it online!

TIO contains test cases for all the states.
-54 bytes thanks to the string compression

\$\endgroup\$
2
  • \$\begingroup\$ You can use the string compression from the other answers to save bytes \$\endgroup\$ Commented Jun 2, 2017 at 11:31
  • 1
    \$\begingroup\$ MINCALA MSCTNMNVAKY WAZ PAR FL GA NHID COKSD ME MDE MA MTX NE NJ NY ND MOH ORIA UT WVT WIL WY is better compression \$\endgroup\$
    – Mayube
    Commented Jun 2, 2017 at 11:38
0
\$\begingroup\$

q/kdb+, 174 bytes

Solution:

{a:" an engineer?";$[(#:)l:ss["ORIA MINCALA MSCTNMNVAKY WAZ PAR FL GA NHID COKSD ME MDE MA MTX NE NJ NY ND MOH UT WVT WIL WY";x];-1_"I am",$[l~(),0;" not";""],a;"What is",a]}

Explanation:

  {
  // save string into variable a
  a:" an engineer?";
  // try to find the input x in the condensed string, save location in variable l, $ is a if/else
  $[(#:)l:ss["ORIA MINCALA MSCTNMNVAKY WAZ PAR FL GA NHID COKSD ME MDE MA MTX NE NJ NY ND MOH UT WVT WIL WY";x];
  // found a match, check if it was at index 0 ('OR') and inject " not" if so, drop the '?' off the end
  -1_"I am",$[l~(),0;" not";""],a;
  // otherwise return 'What is an engineer?'
  "What is",a]
  }

Notes:

Used the 'compressed' string from other answers, struggling to find a way to bring it into a single line in order to avoid assignment of the a variable (yet still add the ? when input is not a state.

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

Retina, 175 bytes

..
I am $&~MINCALAZ SCT FL GA WIAKSD ME MD MA MNMS MOKY MTNE NVTX NH NJ NY ND COHIDE PARIL UT VA WA WV WY
(..)~.*\1.*
~
OR~.*
not ~
I am ..~.*
What is ~?
~
an engineer

Try it online! Hopefully I've appropriated the best state list. Explanation:

..
I am $&~MINCALAZ SCT FL GA WIAKSD ME MD MA MNMS MOKY MTNE NVTX NH NJ NY ND COHIDE PARIL UT VA WA WV WY

Start building up the result. Also, insert the state list for use by the next stage.

(..)~.*\1.*
~

If it's one of the 49 states, delete the state and list.

OR~.*
not ~

If it's Oregon, replace the state with not, and delete the list.

I am ..~.*
What is ~?

If it's anything else, replace everything with the other output.

~
an engineer

Add these word in last to avoid repetition.

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

Crystal, 232 207 205 Bytes

i="ORALAKAZARCACOCTDEFLGAHIIDILINIAKSKYLAMEMDMAMIMNMSMOMTNENVNHNJNMNYNCNDOHOKPARISCSDTNTXUTVTVAWAWVWIWY".split(/(..)/).index ARGV[0];p (i ?"I am ": "What is ")+(i==1 ?"not ": "")+"an engineer"+(i ?"": "?")

Try it online. (slightly modified due to an issue of ARGV)

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

Factor, 135 bytes

USE: usa-cities [ " an engineer"swap [ "I am"swap string>state OR = 
[ " not"append ] when ""] [ 2drop "What is" "?"] recover surround ]

More readable, and named:

: engineer? ( state-name -- str ) 
  [ " an engineer" ] dip ! put this below the input on the stack 
  [ 
    [ "I am" ] dip       ! put this below the input too but above the other 
    string>state OR =    ! string>state throws on a non-state name 
    [ " not" append ] when ""  ! otherwise and if it is OR, append this 
  ] 
  [ 2drop "What is" "?" ] recover surround ; ! catch error, surround string

[ x ] dip and x swap are equivalent in stack effect but the first is shorter only when nested: [ [ [ x ] dip ] dip ] dip.

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

Python 2, 213 211 194 Bytes

c="uTXnMSCORIDEwVAKYmTNHILfLAZpALmNEmOKSDwINCARmEwAnJnDmAmIAgAwYcTnVToHnYmD"
r=(lambda x:x in c or x[0].lower()+x[1]in c)(i)^1
u="What is "*r+("I am "+"not "*(i=="OR"))*(r^1)+"an engineer"+"?"*r

Try It Online

Stuff i'm working on shortening:

  • (i=="OR")
  • or x[0].lower()+x[1]in c

Update:

  • Saved 2 Bytes by replacing s=not r with s=r^1
  • Separated header and footer of code
\$\endgroup\$
0
\$\begingroup\$

Ruby, 164 bytes

->s{r="What is an engineer?"
j=379
"##(*Q0'7q;N>%*$o(.F%#&'#&#5##%$%+%5%)5r@#P,B353*/%".bytes{|i|s==(j+=i-34).to_s(36).upcase&&r="I am not"[0,i==41?8:4]+r[7,12]}
r}

Uses a run length encoding, therefore magic string is 50 bytes long, one per state. In order to build this, it was first necessary to put the state codes in alphabetical order of state code, rather than state name. Unfortunately 7 bytes are needed to convert the base36 representation of j from a lowercase statecode into an uppercase statecode.

Ungolfed in test program

f=->s{                                                  #s is the input string.
  r="What is an engineer?"                              #Set r to "What is an engineer?"
  j=379                                                 #Set j to one less than 380, which in base36 becomes AK, the first statecode alphabetically
  "##(*Q0'7q;N>%*$o(.F%#&'#&#5##%$%+%5%)5r@#P,B353*/%". #Iterate through the run length encoded string 
  bytes{|i|                                             #(each character represents how far in base 36 each state code is from the previous one)
    s==(j+=i-34).to_s(36).upcase&&                      #take the ascii value of the character and subtract 34 (example #=35-34=1) and add to j. Convert j to base36 to get a state code.
      r="I am not"[0,i==41?8:4]+r[7,12]                 #if the state code matches s, modify r. Take the first 4 characters of "I am not" (first 8 in the case of OR where i==41) 
  }                                                     #and add r[7,12]==" an engineer" (12 characters of the existing value of r, starting at character 7 
r}                                                      #return r

%w{AL AK AZ AR CA CO CT DE FL GA HI ID IL IN IA KS KY LA ME MD MA MI MN MS MO MT NE NV NH NJ NM NY NC ND OH OK OR PA RI SC SD TN TX UT VT VA WA WV WI WY XX}.map{|i|p [i,f[i]]}
\$\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.