# Am I happy or sad? [duplicate]

You are trying to guess my emotion.

I will give you an adjective, as the input to the function/program.

Your task is to output my emotion, either :) for happy, or :( for sad.

# Details

For these adjectives, you must output the happy face :)

contented
delighted
merry
overjoyed
blessed
chipper
content
convivial
gleeful
gratified
intoxicated
jolly
light
peppy
perky
playful
sparkling
sunny


For these adjectives, you must output the sad face :(

melancholy
bitter
somber
dismal
mournful
blue
dejected
despairing
despondent
disconsolate
distressed
down
downcast
gloomy
glum
heavyhearted
lugubrious
morbid
morose
troubled
bereaved


Other adjectives are undefined. You may output whatever you want for other adjectives.

# Specs

• All in lowercase. All matches regex ^[a-z]+$. # Scoring This is . Shortest solution in bytes wins. # Tips There is a trick. • This isn't very interesting, basically is input in this set. – Rɪᴋᴇʀ May 1 '16 at 13:30 • @EᴀsᴛᴇʀʟʏIʀᴋ Well, input.length % 2 is even less interesting... – user81655 May 1 '16 at 13:31 • The problem with this type of question is that once the bag, you have a completely different challenge. – Dennis May 1 '16 at 15:11 • melancholy is not an adjective – Luis Mendo May 1 '16 at 17:03 • Melancholy is an adjective. – Leaky Nun May 2 '16 at 0:07 ## 14 Answers ## CJam, 9 bytes ':q,"()"=  The "trick" is the parity of the word lengths. Test it here. ### Explanation ': e# Push character ':'. q, e# Get length of input. "()"= e# Using length as cyclic index into "()", giving '(' for even lengths e# and ')' for odd lengths.  • Could you share with us how you discovered the trick? – Leaky Nun May 1 '16 at 13:30 • @KennyLau By looking at the inputs I guess. It's fairly obvious (visually) that your word lengths are always taking steps in multiples of 2. – Martin Ender May 1 '16 at 13:32 • @MartinBüttner speak for yourself, I would never notice that. – Bálint May 1 '16 at 13:34 • @Bálint Well I wouldn't have either if I hadn't been looking for it, due to Kenny's hint. – Martin Ender May 1 '16 at 13:35 • me too i wudnt notice, was wastin my time finding connection between ascii patterns – Abr001am May 1 '16 at 13:45 # Brainfuck, 71 bytes +[--------->+<]>+.>,+[[-]>[->+<]+>[<->-]<<,+]>[<<+>>-]<+++[<------>-]<.  Assumes that EOF = -1. Explaination: The first part, +[--------->+<]>+., prints : and stores its ascii value (58) in cell #2. The second part, >,+[[-]>[->+<]+>[<->-]<<,+], is a bit more complicated. For each character in the input, it moves the value in cell #4 into cell #5, it adds one to cell #4, and sets cell #4 = cell #4 - cell #5. Basically, what this does is it changes cell #4 into 1 - cell #4. When every character has been read, cell #4 is length of input % 2. The third part, >[<<+>>-] adds the value of cell #4 to cell #2. The last part, >,+[[-]>[->+<]+>[<->-]<<,+] subtracts 18, which is the difference in the ascii table from the colon and the left parentesens from cell #2 and prints it. # J, 15 bytes ':',"0'()'{~2|#  ':',"0 concats ':' with the 0-cells of the string '()', making an array of :( and :). {~ is get with switched argument order, 2| is the parity of the length # of the RHS.  p =: ':',"0'()'{~2|# p 'happy' :) p 'somber' :(  Use (>;p)"0 to test a list of words and compare their output. • What does prozac mean? – Leaky Nun May 1 '16 at 16:27 • @KennyLau Bad pun. prozac is a depression medicine :P – Conor O'Brien May 1 '16 at 16:28 • Hahaha, made me laugh for a bit :p – Adnan May 1 '16 at 16:31 • @Adnan Yeah, but I guess it's not the apt place :P – Conor O'Brien May 1 '16 at 16:32 # Reng v.3.3, 12 bytes ":("k2,+roo~  This puts 58, 40 on the stack, gets the length of the input stack, 2, modulos by 2, + adds it to the (, r reverses, oo outputs two characters, and ~ terminates the program. Try it here! Input is like "somber". I don't think we need a GIF for this ;) # 05AB1E, 10 bytes Code: ':žuâ¹gÉ@  Dammit, also 10 bytes: gÉ40+ç':sJ. Uses CP-1252 encoding. Try it online!. # Jelly, 8 bytes Code: ”:³Lị“)(  Explanation: ”: # The ":" character ³L # Get the length of the input ị“)( # Find the index of the length in the ")(" string. # Uses cyclic indexing for indices exceeding the length of the string.  Uses the Jelly-encoding. # MATL, 11 10 bytes 58')('jn)h  1 byte saved thanks to @Luis's tip to just rely upon modular indexing rather than an explicit modulus. Try it Online! Explanation 58 % Number literal (ASCII for ':') ')(' % String literal j % Explicitly grab input as string n % Compute the length of the input string ) % Index into ')(' using modular indexing h % Horizontally concatenate ':' with the result % Implicitly display resulting string  • 58')('jn)h saves 1 byte using modular indexing – Luis Mendo May 1 '16 at 22:14 • @LuisMendo Modular indexing gets me every time! Thanks! – Suever May 1 '16 at 22:16 # Retina, 2118 14 bytes (..)+ :( \(. )  3 bytes saved thanks to Martin Büttner. Another 4 saved thanks to Kenny Lau. Try it online! (The first line is just to make it run for all test cases). Uses the same approach as Martins answer. # Fuzzy Octo Guacamole, 22 bytes ^!_2rm{':('0}i{':)'1}_  Gets input, finds length%2, prints :) vs :( for on a remainder of 1 or 0. # Lua, 3534 30 bytes print(#(...)%2>0 and":)"or":(")  • Use <1 instead of ==0 to save a byte :) – Leaky Nun May 1 '16 at 14:06 • use (...) instead of io.read() to save 3 bytes :) – Leaky Nun May 1 '16 at 14:06 • print(#(...)%2 and":)"or":(") just skip the <1 already – Leaky Nun May 1 '16 at 14:08 • But (...) doesn't take input :( – user6245072 May 1 '16 at 14:14 • But it's allowed. – Leaky Nun May 1 '16 at 14:18 # Jolf, 12 11 bytes +':."()"mρl  I might (might) be was able to golf it down a byte by joining the faces. Try it here! ## Explanation +':."()"mρl +': ":" + ."()" the member from "()" mρl that is the parity of the length of the implicit input  # Javascript 30 bytes a=>alert(a.length%2?":)":":(")  # Javascript return version 23 bytes a=>a.length%2?":)":":("  Try it out: b=a=>a.length%2?":)":":(" alert(b(prompt("Please enter how you feel!"))); • Since it's a function, I think you can just return the result. – Conor O'Brien May 1 '16 at 16:11 • @CᴏɴᴏʀO'Bʀɪᴇɴ You need to output it. – Bálint May 1 '16 at 18:20 • See my javascript answer for what I'm talking about. – Conor O'Brien May 1 '16 at 18:24 # JavaScript ES6, 23 bytes x=>":"+"()"[x.length%2]  Simple anonymous function. ## Test f = x => ":" + "()" [x.length % 2]; makeRow = (x, y) => t.innerHTML += <tr><td>${x}</td><td>${y}</td></tr>; contented delighted merry overjoyed pleased blessed chipper content convivial gleeful gratified intoxicated jolly light peppy perky playful sparkling sunny.split(\n).forEach(e => makeRow(e, f(e))); t.innerHTML += "<tr><th colspan=2>Sad cases</th></tr>"; melancholy bitter somber dismal mournful blue dejected despairing despondent disconsolate distressed down downcast gloomy glum heavyhearted lugubrious morbid morose troubled bereaved.split(\n).forEach(e => makeRow(e, f(e))); html { font-family: Consolas, monospace; } table { border-collapse: collapse; } td, th { padding: 10px; border: 1px solid; } <table id="t"> <tr> <th>Word</th> <th>Output</th> </tr> <tr> <th colspan=2>Happy cases</th> </tr> </table> • what is the type of x? – Leaky Nun May 1 '16 at 16:50 • @KennyLau x is a string. – Conor O'Brien May 1 '16 at 16:50 • javascript does not require x.length()? – Leaky Nun May 1 '16 at 16:53 • @KennyLau Nope, .length is a method that changes with the object. – Conor O'Brien May 1 '16 at 16:53 • It's shorter to just use ":(" or ":)" – Bálint May 1 '16 at 18:22 ## Labyrinth, 14 bytes 4 1 #$
;,98..@


Try it online!

### Explanation

Labyrinth primer:

• Labyrinth has two stacks of arbitrary-precision integers, main and aux(iliary), which are initially filled with an (implicit) infinite amount of zeros.
• The source code resembles a maze, where the instruction pointer (IP) follows corridors when it can (even around corners). The code starts at the first valid character in reading order, i.e. in the top left corner in this case. When the IP comes to any form of junction (i.e. several adjacent cells in addition to the one it came from), it will pick a direction based on the top of the main stack. The basic rules are: turn left when negative, keep going ahead when zero, turn right when positive. And when one of these is not possible because there's a wall, then the IP will take the opposite direction. The IP also turns around when hitting dead ends.
• Digits are processed by multiplying the top of the main stack by 10 and then adding the digit. If the top of the stack is negative, the digit is subtracted instead.

The code starts in the top left corner, with the IP moving south. The 41 simply turns the top 0 on the main stack into 41, the character code of ).

We now enter a 2x2 (clockwise) loop which reads one character at a time, and toggles the top of the stack between 40 (() and 41 ()):

#   Push the stack depth, which is 1.
\$   XOR the top two values on the stack, toggling between 40 and 41.
,   Read a character (positive value) or -1 at EOF. At EOF, we exit the loop.

At the end of the loop, the main stack has the correct character code for either ( or ) and a -1 on top of that. The rest of the code is linear.
98  Turn the -1 on top of the stack into -198.

• @KennyLau )`'s char code is 41, so I bet it has something to with that. – Conor O'Brien May 1 '16 at 16:35