| Bytes | Lang | Time | Link |
|---|---|---|---|
| 024 | AWK | 250902T161116Z | xrs |
| 005 | Thunno 2 tB | 230719T142128Z | The Thon |
| 2319 | Raku p 23 Bytes > 19 Bytes | 200404T035246Z | Sebastia |
| 007 | Vyxal K | 210606T025840Z | emanresu |
| 094 | brainfuck | 210812T175528Z | nununois |
| 2335 | JavaScript | 200723T233851Z | General |
| 010 | Golfscript | 210606T045351Z | EsoJihun |
| 020 | Factor | 210606T021508Z | chunes |
| 099 | batch | 200402T155219Z | T3RR0R |
| 014 | Perl 5 p | 200930T055045Z | Chris |
| 020 | sed | 200930T054429Z | Chris |
| 027 | MAWP | 200723T142927Z | Dion |
| 011 | International Phonetic Esoteric Language | 200623T175932Z | bigyihsu |
| 027 | MAWP 0.1 | 200622T185155Z | Dion |
| 029 | JavaScript | 200609T220539Z | Bardic W |
| 025 | Python 3 | 200401T194542Z | Dion |
| 1820 | Mornington Crescent | 200427T014448Z | Cloudy7 |
| 008 | Pyth | 200402T084508Z | Mukundan |
| 038 | Wolfram Language Mathematica | 200405T022242Z | DanTheMa |
| 016 | PowerShell | 200404T202715Z | Veskah |
| 033 | Hy | 200403T202142Z | xikuuky |
| 014 | C# Visual C# Interactive Compiler | 200402T122304Z | the defa |
| 009 | J | 200403T063221Z | Galen Iv |
| 011 | GolfScript | 200403T193742Z | Mathgeek |
| 034 | TSQL | 200403T161202Z | Brian J |
| 033 | C gcc | 200401T162331Z | Arnauld |
| 024 | Kotlin | 200402T120531Z | snail_ |
| 026 | Python 3 | 200401T165849Z | Uriel |
| 007 | W | 200402T075533Z | user9206 |
| 025 | Excel | 200402T121507Z | Wernisch |
| 032 | Red | 200402T091052Z | Galen Iv |
| 008 | APL Dyalog | 200401T163323Z | Uriel |
| 017 | Bash + GNU utilities | 200402T012552Z | Mitchell |
| 008 | 05AB1E | 200402T031446Z | PkmnQ |
| 018 | Keg | 200402T022524Z | lyxal |
| 120 | naz | 200402T021158Z | sporebal |
| 019 | Raku | 200402T013431Z | Jo King |
| 032 | Erlang escript | 200402T010044Z | user9206 |
| 031 | Io | 200402T005159Z | user9206 |
| 009 | MATL | 200401T225557Z | Luis Men |
| 009 | Japt | 200401T232215Z | Shaggy |
| 007 | Jelly | 200401T211000Z | Jonathan |
| 010 | Charcoal | 200401T205057Z | Neil |
| 012 | Retina 0.8.2 | 200401T181305Z | math jun |
| 020 | Ruby | 200401T190410Z | dingledo |
| 024 | Perl 5 p | 200401T170834Z | Xcali |
| 027 | Python 3 | 200401T162433Z | RGS |
Thunno 2 tB, 5 bytes
ṇ;Œ7%
Uses dingledooper's formula.
Explanation
ṇ;Œ7% # Implicit input
# Convert to codepoints
ṇ; # Push compressed integer 160
Œ # Take 160 mod each codepoint
7% # Mod each by 7
# Implicit output of last item
Raku -p 23 Bytes -> 19 Bytes
$_=(4-.ords[*-1]*2%5)%4
$_=160%.ords[*-1]%7 #(with @dingledooper's formula)
brainfuck, 94 bytes
,[[>++<-]>>,]>++++[<++++>-]<[+++<[>->+<[>]>[<+>-]<<[<]>-]>[-]<<<[>>>>>+<<]>>]>-[>+<-----]>---.
Uses Uriel's formula. Here's how it works:
,[[>++<-]>>,]
A nifty input loop that handles the optional nose and doubling the characters. It gets a character, doubles it into the next cell, then moves two cells over and tries to get another character. At the end, the tape looks something like
0 2*c1 0 2*c2 0 2*c3 0 ...
^
This requires an implementation with EOF=0 or no change (which accounts for most of them including TIO).
>++++[<++++>-]<
Put 16 after the last doubled input. Now on to the main loop:
[+++<[>->+<[>]>[<+>-]<<[<]>-]>[-]<<<[>>>>>+<<]>>]
This loop will
- add 3 to the dividend (current cell). I do this because it's 2 bytes shorter to get 16 rather than 19, and these can be reused to construct 4 for the second dividend.
- compute the modulus of the previous%current cell.
- clear out a temporary variable
- check if the value of the cell 3 indices back is non-zero (which is only true on the first iteration since the loop ends 2 indices to the right of where it started). If it is, increment the cell where the next dividend will be (this sets up the second modulo 4).
For clarity, here's what the tape looks like during the first iteration, before the tempvar is cleaned:
0 2*c1 0 2*c2 0 0 tmp 2*c3%19 0 ...
^
And the same for the second:
0 2*c1 0 2*c2 0 0 0 0 tmp 2*c3%19%4 0 ...
^
So checking the cell 3 indices back is an easy way to see which iteration we're on without using a counter.
>-[>+<-----]>---.
And finally, a bit of wrapping abuse to add 48 to the result so it can be outputted.
There's probably room for improvement, particularly in the input loop or the memory layout, but this is the best I could come up with.
JavaScript, 2335
(・・? Did somebody say emoticons?
a =
// The function:
(w)=>{(笑)=(w);゚ω゚ノ= /`m´)ノ ~┻━┻ //*´∇`*/ ['_']; o=(゚ー゚) =_=3; c=(゚Θ゚) =(゚ー゚)-(゚ー゚); (゚Д゚) =(゚Θ゚)= (o^_^o)/ (o^_^o);(゚Д゚)={゚Θ゚: '_' ,゚ω゚ノ : ((゚ω゚ノ==3) +'_') [゚Θ゚] ,゚ー゚ノ :(゚ω゚ノ+ '_')[o^_^o -(゚Θ゚)] ,゚Д゚ノ:((゚ー゚==3) +'_')[゚ー゚] }; (゚Д゚) [゚Θ゚] =((゚ω゚ノ==3) +'_') [c^_^o];(゚Д゚) ['c'] = ((゚Д゚)+'_') [ (゚ー゚)+(゚ー゚)-(゚Θ゚) ];(゚Д゚) ['o'] = ((゚Д゚)+'_') [゚Θ゚];(゚o゚)=(゚Д゚) ['c']+(゚Д゚) ['o']+(゚ω゚ノ +'_')[゚Θ゚]+ ((゚ω゚ノ==3) +'_') [゚ー゚] + ((゚Д゚) +'_') [(゚ー゚)+(゚ー゚)]+ ((゚ー゚==3) +'_') [゚Θ゚]+((゚ー゚==3) +'_') [(゚ー゚) - (゚Θ゚)]+(゚Д゚) ['c']+((゚Д゚)+'_') [(゚ー゚)+(゚ー゚)]+ (゚Д゚) ['o']+((゚ー゚==3) +'_') [゚Θ゚];(゚Д゚) ['_'] =(o^_^o) [゚o゚] [゚o゚];(゚ε゚)=((゚ー゚==3) +'_') [゚Θ゚]+ (゚Д゚) .゚Д゚ノ+((゚Д゚)+'_') [(゚ー゚) + (゚ー゚)]+((゚ー゚==3) +'_') [o^_^o -゚Θ゚]+((゚ー゚==3) +'_') [゚Θ゚]+ (゚ω゚ノ +'_') [゚Θ゚]; (゚ー゚)+=(゚Θ゚); (゚Д゚)[゚ε゚]='\\'; (゚Д゚).゚Θ゚ノ=(゚Д゚+ ゚ー゚)[o^_^o -(゚Θ゚)];(o゚ー゚o)=(゚ω゚ノ +'_')[c^_^o];(゚Д゚) [゚o゚]='\"';(゚Д゚) ['_'] ( (゚Д゚) ['_'] (゚ε゚+(゚Д゚)[゚o゚]+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ (゚ー゚)+ (゚Θ゚)+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ ((゚ー゚) + (゚Θ゚))+ (゚ー゚)+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ (゚ー゚)+ ((゚ー゚) + (゚Θ゚))+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ ((o^_^o) +(o^_^o))+ ((o^_^o) - (゚Θ゚))+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ ((o^_^o) +(o^_^o))+ (゚ー゚)+ (゚Д゚)[゚ε゚]+((゚ー゚) + (゚Θ゚))+ (c^_^o)+ (゚Д゚)[゚ε゚]+(゚ー゚)+ ((゚ー゚) + (o^_^o))+ (゚Д゚)[゚ε゚]+((゚ー゚) + (゚Θ゚))+ (c^_^o)+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ ((゚ー゚) + (o^_^o))+ (゚ー゚)+ (゚Д゚)[゚ε゚]+((゚ー゚) + (゚Θ゚))+ (゚Θ゚)+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ (c^_^o)+ (゚ー゚)+ (゚Д゚)[゚ε゚]+(゚ー゚)+ ((゚ー゚) + (o^_^o))+ (゚Д゚)[゚ε゚]+((゚ー゚) + (゚Θ゚))+ ((o^_^o) +(o^_^o))+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ ((゚ー゚) + (゚Θ゚))+ (゚Θ゚)+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ ((゚ー゚) + (゚Θ゚))+ ((o^_^o) +(o^_^o))+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ (゚ー゚)+ (゚ー゚)+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ (゚ー゚)+ ((゚ー゚) + (゚Θ゚))+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ ((゚ー゚) + (o^_^o))+ (c^_^o)+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ (゚Θ゚)+ ((゚ー゚) + (o^_^o))+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ (゚ー゚)+ ((o^_^o) +(o^_^o))+ (゚Д゚)[゚ε゚]+((゚ー゚) + (゚Θ゚))+ (c^_^o)+ (゚Д゚)[゚ε゚]+(o゚ー゚o)+ ((゚ー゚) + (o^_^o))+ (゚Д゚) .゚Θ゚ノ+ (゚Θ゚)+ (゚Θ゚)+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ (o^_^o)+ (o^_^o)+ (゚Д゚)[゚ε゚]+((o^_^o) +(o^_^o))+ ((o^_^o) - (゚Θ゚))+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ (o^_^o)+ ((゚ー゚) + (゚Θ゚))+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ ((゚ー゚) + (o^_^o))+ (゚ー゚)+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ ((゚ー゚) + (o^_^o))+ (゚ー゚)+ (゚Д゚)[゚ε゚]+(o゚ー゚o)+ ((゚ー゚) + (o^_^o))+ (゚Д゚) .゚Θ゚ノ+ (゚Θ゚)+ (゚Θ゚)+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ (o^_^o)+ (o^_^o)+ (゚Д゚)[゚ε゚]+((o^_^o) +(o^_^o))+ (゚Θ゚)+ (゚Д゚)[゚ε゚]+(゚Θ゚)+ (o^_^o)+ ((゚ー゚) + (゚Θ゚))+ (゚Д゚)[゚ε゚]+((゚ー゚) + (゚Θ゚))+ (゚Θ゚)+ (゚Д゚)[゚ε゚]+((゚ー゚) + (゚Θ゚))+ (゚Θ゚)+ (゚Д゚)[゚o゚]) (゚Θ゚)) ('_');}
// Execute function:
a(':D');
I took it from this answer, encoded it with aaencode, and wrapped it an the arrow function.
Golfscript, 10 bytes
-1='(|)D'?
Explanation:
-1= # Gets the ASCII value of the final character.
'(|)D'? # Finds the index of that ASCII value, in the string '(|)D'.
And then, the index value is implicitly printed.
Factor, 20 bytes
[ last "(|)D"index ]
Explanation:
If ":)" is on the data stack when this quotation is called...
lastTake the last element of the input.Stack:
41(code point for))"(|)D"Push a string to the stack.Stack:
41 "(|)D"indexFind the index of41in"(|)D".Stack:
2
batch, 109 bytes 99 bytes
@For %%G in ("(=0",")=2","D=3","|=1")Do @Set %%G
@Set "T=%~1"
@<Nul Call Call Set/P"=%%%T:~-1%%%"
Perl 5 -p, 14 bytes
y/(|)D:-/0-3/d
Basically a port of my sed answer, but the y/// command in perl has the additional utilities of deleting extra characters and specifying ranges of characters, so this manages to be shorter and still contain :-/ and D: as essential parts of the code.
sed, 20 bytes
y/(|)D/0123/;s/:-*//
Pretty self explanatory. Replaces the the "mouth" characters with numbers using the y/// transform command and then strips off the eyes and the nose if they exist.
This is one byte longer, but perhaps it gets bonus points for having an emoticon in the code itself? :-\
y/(|)D/0123/;s/:-\?//
The shorter solution (16 bytes)
y/(|)D:-/0123 /
also works, but adds extra whitespace to each line of output. It also has two emoticons D: and :-/. :)
International Phonetic Esoteric Language, 11 bytes
iʁ2f{J}ⱱ4ⱱo
Based on Uriel's formula.
iʁ2f{J}ⱱ4ⱱo
iʁ (split the face into it's ord values)
2f (mouth * 2)
{J}ⱱ (mod 19) (base 26)
4ⱱ (mod 4)
o (print)
JavaScript, 35 32 29 bytes
I based the logic off of the Java solution submitted April 2 and edited April 8, by branboyer. I suppose it would be referred to as a port of their answer, but I don’t know exactly how that’s supposed to be marked.
a=>"(|)D".indexOf(a[2]||a[1])
An anonymous function, taking a string and returning an integer. Please help me shorten it further, I’m new to golfing code. Just the code, without the way of inputting (no idea how to get input in try it online) is at this Try it online link
Mornington Crescent, 1820 bytes
A port of @dingledooper's fantastic Ruby answer, which just so happens to work seamlessly in Mornington Crescent because of a convenient 7 in it. Props to them!
Take Northern Line to Leicester Square
Take Northern Line to Leicester Square
Take Piccadilly Line to Turnpike Lane
Take Piccadilly Line to Turnpike Lane
Take Piccadilly Line to Leicester Square
Take Northern Line to Leicester Square
Take Northern Line to Charing Cross
Take Northern Line to Charing Cross
Take Bakerloo Line to Baker Street
Take Bakerloo Line to Paddington
Take Bakerloo Line to Charing Cross
Take Bakerloo Line to Charing Cross
Take Northern Line to Moorgate
Take Circle Line to Moorgate
Take Metropolitan Line to Chalfont & Latimer
Take Metropolitan Line to King's Cross St. Pancras
Take Victoria Line to Seven Sisters
Take Victoria Line to Victoria
Take Circle Line to Victoria
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Cannon Street
Take Circle Line to Hammersmith
Take Circle Line to Cannon Street
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Victoria
Take Circle Line to Victoria
Take Circle Line to Aldgate
Take Circle Line to Aldgate
Take Metropolitan Line to Chalfont & Latimer
Take Metropolitan Line to Preston Road
Take Metropolitan Line to Baker Street
Take Metropolitan Line to Preston Road
Take Metropolitan Line to Pinner
Take Metropolitan Line to Preston Road
Take Metropolitan Line to King's Cross St. Pancras
Take Victoria Line to Seven Sisters
Take Victoria Line to King's Cross St. Pancras
Take Circle Line to King's Cross St. Pancras
Take Metropolitan Line to Pinner
Take Metropolitan Line to Preston Road
Take Metropolitan Line to Pinner
Take Metropolitan Line to Preston Road
Take Metropolitan Line to King's Cross St. Pancras
Take Circle Line to King's Cross St. Pancras
Take Northern Line to Mornington Crescent
The only major thing I feel I need to point out is how I got 160 in the program. To do this, I took the first letter of Paddington, which gives an ASCII value of 80 when run through Charing Cross, then multiplied it by 2 in Chalfont & Latimer to get 160. Subsequently, the program computes 160 % (ASCII of last character) % 7 via Preston Road, the formula found by @dingledooper.
Pyth, 8 bytes
x"(|)D"e
Exalanation
x"(|)D"e
: Implicit evaluated input
e : Last element of input
"(|)D" : The string "(|)D"
x : First occurrence of the last element of input in "(|)D"
Wolfram Language (Mathematica), 38 bytes
Mod[2Last@ToCharacterCode@#,19]~Mod~4&
This borrows Uriel's formula, which happens to be the same length as dingledooper's, but I can't help but wonder if another formula would be shorter. I will investigate.
For comparison, here's the string indexing solution (51 bytes):
("(|)D"~StringPosition~Last@Characters@#)[[1, 1]]-1&
PowerShell, 16 bytes
2*$args[-1]%19%4
PowerShell port of the modulo formula going around. Takes input via splatting
Hy, 33 bytes
(fn[s](%(%(*(ord(last s))2)19)4))
It's a basic port of Uriel's answer. I might be able to shorten it by getting rid of a % but I need to play around with the syntax.
C# (Visual C# Interactive Compiler), 17 14 bytes
Turns out Ranges finally started to actually exist and work! Thanks to an anonymous user for pointing this out (by proposing an edit, but anonymous users cannot comment...)
s=>160%s[^1]%7
GolfScript, 11 bytes
)3?11%2/(p;
I'm convinced my method is the smallest possible, but this isn't the best possible one - just one of the earliest low-value ones.
)3?11%2/(p;
) #Pop the last element of the string (as ascii value)
3? #Cube the number
11% #Modulo 11
2/ #Divide by 2 (round down)
( #Decrement by one (gotta be 0 1 2 3, not 1 2 3 4)
p; #Print the value we want, and shunt the rest of the stack
I used the following TIO to search for answers, and 11 popped up quite early. I also tried squares and higher powers, but they weren't as clean and short.
T-SQL, 34 bytes
SELECT CHARINDEX(RIGHT(@,1),'|)D')-1
Requires the variable @ to be declared and assigned the input.
This code takes the right most character, and searches an indexed list of the possible mouthes. CHARINDEX returns a 1-based index. But, failing to find anything returns 0. So we leave the frown out of the search string (making the sad face even sadder).
C (gcc), 37 33 bytes
Saved 4 bytes on both versions thanks to @ceilingcat and @dingledooper
I overlooked the rule about the optional nose, so this is not as effective as expected.
f(char*s){s=390%~-s[*++s%9<1]&3;}
How?
Among the characters that we have to deal with, the hyphen is the only one whose ASCII code is congruent to \$0\$ modulo \$9\$. We use this property to decide whether we need to work on the second or the third character.
Given the ASCII code \$n\$ of the relevant smiley character, we apply the following formula to get the happiness:
$$h(n)=(390\bmod (n-1))\bmod 4$$
C (gcc), 36 32 bytes
Using Uriel's formula is 1 byte shorter.
f(char*s){s=s[*++s%9<1]*2%19&3;}
W, 7 bytes
☻M:ù·±♥
Uncompressed:
(|)D"azx
Explanation
% Implicit quote
(|)D" % The string "(|)D"
az % The last item of the input
x % Where is ^ in the above string?
Excel, 25 bytes
=FIND(RIGHT(A1),"(|)D")-1
APL (Dyalog), 11 8 bytes
3 bytes saved thanks to @Bubbler!
⊃'(|)'⍳⌽
⌽ reverse the string
⊃ take the last (now first) byte
'(|)'⍳ index inside '(|)' (if not found ('D') returns the length (3))
Bash + GNU utilities, 17 bytes
tr '(|)D:-' 0-3\
Note: There's a space character after the backslash.
Input on stdin, output on stdout.
The challenge doesn't specify the format of the output. Depending on the input, this program may print the output in either %2d or %3d format (that is, with one or two spaces before the 0, 1, 2, or 3).
If that's not acceptable, then
tr -s '(|)D:-' 0-3\
(20 bytes) always prints the digit in %2d format. (There's a space after the backslash here too.)
Or
tr '(|)D:-' 0-4|tr -d 4
(23 bytes) prints just the digit (with no spaces).
05AB1E, 8 bytes
θÇx19%4%
Explanation
I used Uriel's formula.
θ # Get mouth (last char)
Ç # ASCII value
x # Multiply by 2
19% # Modulo 19
4% # Modulo 4
Keg, -hr, 18 bytes
?^⑵¦P0|\🄃1|R2|\¦3™
The same switch statement format, but with a different character checking criteria.
naz, 120 bytes
8a5m2x1v1a2x2v4a2x3v9a9a5a2x4v1x1f2r3x3v1e2f0x1x2f3x1v3e3x2v5e3x4v6e4f0x1x3f0m1o0x1x4f0m1a1o0x1x5f0m2a1o0x1x6f0m3a1o0x1f
Explanation (with 0x commands removed)
8a5m2x1v # Set variable 1 equal to 40 ("(")
1a2x2v # Set variable 2 equal to 41 (")")
4a2x3v # Set variable 3 equal to 45 ("-")
9a9a5a2x4v # Set variable 4 equal to 68 ("D")
1x1f # Function 1
2r # Read the second byte in the input string, removing it
3x3v1e # Jump back to the start of the function if it equals variable 3
2f # Otherwise, jump to function 2
1x2f # Function 2
3x1v3e # Jump to function 3 if the register equals variable 1
3x2v5e # Jump to function 5 if the register equals variable 2
3x4v6e # Jump to function 6 if the register equals variable 4
4f # Otherwise, jump to function 4
1x3f # Function 3
0m1o # Output 0
1x4f # Function 4
0m1a1o # Output 1
1x5f # Function 5
0m2a1o # Output 2
1x6f # Function 6
0m3a1o # Output 3
1f # Call function 1
Io, 31 bytes
Io's strings are made of integers, so character-converting is unneccecary. Although Io doesn't allow us to index the last item of a sequence using last()...
method(x,160%x reverse at(0)%7)
MATL, 9 bytes
'|)D'jmfs
Explanation
'|)D' % Push this string
j % Read input as unevaluated string
m % ismember: true for chars of the first string that are present in the second
f % find: (1-based) indices of true entries. The result will have length 0 or 1
s % sum. This is needed to transform an empty array into 0
% Implicitly display
Jelly, 8 7 bytes
⁽$9,4ḥ’
A monadic Link accepting a list of characters which yields an integer in \$[0,3]\$.
How?
⁽$9,4ḥ’ - Link: list of characters, A
⁽$9 - base 250 literal = 10058
,4 - pair with four
ḥ - Jelly hash A using 10058 as a salt and [1,2,3,4] as the domain
’ - decrement
Previous 8 byter:
“|)D”iⱮS
How?
“|)D”iⱮS - Link: list of characters, A e.g. ":-)" OR ":-("
Ɱ - map across c in A with:
i - first index of c in (or 0 if not found):
“|)D” - list of characters = "|)D" [0,0,2] [0,0,0]
S - sum 2 0
Charcoal, 10 bytes
I⌕(|)D§S±¹
Try it online! Link is to verbose version of code. Explanation:
S Input string
§ Cyclically indexed by
¹ Literal 1
± Negated
⌕ Find index in
(|)D Literal string of mouths
I Cast to string
Implicitly print
Retina 0.8.2, 16 12 bytes
T`-:(|)D`__d
T`
Enter transliteration mode
(|)D`d
Replace the mouth character with the corresponding digit (0 to 3)
-:`__
Remove each of - and : from the string.
Implicitly output the result, which will be a single digit.
Ruby, 20 bytes
s[-1].ord will give us the codepoint of the last character in the string, which we can then plug into this formula:
$$(160 \bmod c) \bmod 7 $$
->s{160%s[-1].ord%7}
Python 3, 28 27 bytes
lambda e:"(|)D".find(e[-1])
Because we don't care about the eyes/nose, we can just look at the mouth (the last character) and find its index in a string with all the mouths, ordered from saddest to happiest :) Thanks @Surculose Sputum!
