-10
\$\begingroup\$

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

\$\endgroup\$
7
  • 3
    \$\begingroup\$ This isn't very interesting, basically is input in this set. \$\endgroup\$
    – Riker
    May 1, 2016 at 13:30
  • 5
    \$\begingroup\$ @EᴀsᴛᴇʀʟʏIʀᴋ Well, input.length % 2 is even less interesting... \$\endgroup\$
    – user81655
    May 1, 2016 at 13:31
  • 2
    \$\begingroup\$ The problem with this type of question is that once the bag, you have a completely different challenge. \$\endgroup\$
    – Dennis
    May 1, 2016 at 15:11
  • \$\begingroup\$ melancholy is not an adjective \$\endgroup\$
    – Luis Mendo
    May 1, 2016 at 17:03
  • 1
    \$\begingroup\$ Melancholy is an adjective. \$\endgroup\$
    – Leaky Nun
    May 2, 2016 at 0:07

14 Answers 14

2
\$\begingroup\$

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.
\$\endgroup\$
5
  • \$\begingroup\$ Could you share with us how you discovered the trick? \$\endgroup\$
    – Leaky Nun
    May 1, 2016 at 13:30
  • \$\begingroup\$ @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. \$\endgroup\$ May 1, 2016 at 13:32
  • \$\begingroup\$ @MartinBüttner speak for yourself, I would never notice that. \$\endgroup\$
    – Bálint
    May 1, 2016 at 13:34
  • 1
    \$\begingroup\$ @Bálint Well I wouldn't have either if I hadn't been looking for it, due to Kenny's hint. \$\endgroup\$ May 1, 2016 at 13:35
  • \$\begingroup\$ me too i wudnt notice, was wastin my time finding connection between ascii patterns \$\endgroup\$
    – Abr001am
    May 1, 2016 at 13:45
2
\$\begingroup\$

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.

\$\endgroup\$
2
\$\begingroup\$

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.

\$\endgroup\$
4
  • \$\begingroup\$ What does prozac mean? \$\endgroup\$
    – Leaky Nun
    May 1, 2016 at 16:27
  • 2
    \$\begingroup\$ @KennyLau Bad pun. prozac is a depression medicine :P \$\endgroup\$ May 1, 2016 at 16:28
  • \$\begingroup\$ Hahaha, made me laugh for a bit :p \$\endgroup\$
    – Adnan
    May 1, 2016 at 16:31
  • 1
    \$\begingroup\$ @Adnan Yeah, but I guess it's not the apt place :P \$\endgroup\$ May 1, 2016 at 16:32
2
\$\begingroup\$

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 ;)

\$\endgroup\$
2
\$\begingroup\$

05AB1E, 10 bytes

Code:

':žuâ`¹gÉ@

Dammit, also 10 bytes: gÉ40+ç':sJ.

Uses CP-1252 encoding. Try it online!.

\$\endgroup\$
2
\$\begingroup\$

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.

Try it online!.

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

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
\$\endgroup\$
2
  • \$\begingroup\$ 58')('jn)h saves 1 byte using modular indexing \$\endgroup\$
    – Luis Mendo
    May 1, 2016 at 22:14
  • \$\begingroup\$ @LuisMendo Modular indexing gets me every time! Thanks! \$\endgroup\$
    – Suever
    May 1, 2016 at 22:16
2
\$\begingroup\$

Retina, 21 18 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.

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

Fuzzy Octo Guacamole, 22 bytes

^!_2rm{':('0}i{':)'1}_

Gets input, finds length%2, prints :) vs :( for on a remainder of 1 or 0.

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

Lua, 35 34 30 bytes

print(#(...)%2>0 and":)"or":(")
\$\endgroup\$
5
  • \$\begingroup\$ Use <1 instead of ==0 to save a byte :) \$\endgroup\$
    – Leaky Nun
    May 1, 2016 at 14:06
  • \$\begingroup\$ use (...) instead of io.read() to save 3 bytes :) \$\endgroup\$
    – Leaky Nun
    May 1, 2016 at 14:06
  • \$\begingroup\$ print(#(...)%2 and":)"or":(") just skip the <1 already \$\endgroup\$
    – Leaky Nun
    May 1, 2016 at 14:08
  • \$\begingroup\$ But (...) doesn't take input :( \$\endgroup\$ May 1, 2016 at 14:14
  • \$\begingroup\$ But it's allowed. \$\endgroup\$
    – Leaky Nun
    May 1, 2016 at 14:18
1
\$\begingroup\$

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
\$\endgroup\$
1
\$\begingroup\$

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!")));

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Since it's a function, I think you can just return the result. \$\endgroup\$ May 1, 2016 at 16:11
  • \$\begingroup\$ @CᴏɴᴏʀO'Bʀɪᴇɴ You need to output it. \$\endgroup\$
    – Bálint
    May 1, 2016 at 18:20
  • \$\begingroup\$ See my javascript answer for what I'm talking about. \$\endgroup\$ May 1, 2016 at 18:24
1
\$\begingroup\$

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>

\$\endgroup\$
8
  • \$\begingroup\$ what is the type of x? \$\endgroup\$
    – Leaky Nun
    May 1, 2016 at 16:50
  • \$\begingroup\$ @KennyLau x is a string. \$\endgroup\$ May 1, 2016 at 16:50
  • \$\begingroup\$ javascript does not require x.length()? \$\endgroup\$
    – Leaky Nun
    May 1, 2016 at 16:53
  • \$\begingroup\$ @KennyLau Nope, .length is a method that changes with the object. \$\endgroup\$ May 1, 2016 at 16:53
  • \$\begingroup\$ It's shorter to just use ":(" or ":)" \$\endgroup\$
    – Bálint
    May 1, 2016 at 18:22
1
\$\begingroup\$

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.
;   Discard the character.

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.
.   Print the top of the stack, modulo 256. -198 % 256 == 58, the character
    code of ':'.
.   Print the top of the stack, i.e. the mouth of the emoticon.
@   Terminate the program.
\$\endgroup\$
3
  • \$\begingroup\$ Magic, magic numbers. \$\endgroup\$
    – Leaky Nun
    May 1, 2016 at 16:32
  • \$\begingroup\$ @KennyLau )'s char code is 41, so I bet it has something to with that. \$\endgroup\$ May 1, 2016 at 16:35
  • \$\begingroup\$ en.wikipedia.org/wiki/… \$\endgroup\$
    – Leaky Nun
    May 1, 2016 at 16:37

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