[Question]
  [
Two-dimensional programming languages often have mirror commands like `/` and `\` to redirect the instruction pointer on the grid:
```
>>>>\
    v
    v
<<<</
```
In this challenge, you're given an incoming direction and a mirror and you need to determine the outgoing direction.
## Rules
The incoming direction will be given as one of the characters `NESW` and the mirror will be given as either `/` or `\`. You may receive these in any order. You must use uppercase letters.
You may take input in any convenient format, including a two-character string, a string using some separator between the characters, a pair of characters in a list, or even a pair of singleton strings. If you do use a string with separator, the separator cannot use any of the characters `NWSE\/`.
Output should be a character from `NESW` or single-character string.
You may write a [program or a function](http://meta.codegolf.stackexchange.com/q/2419) and use any of the our [standard methods](http://meta.codegolf.stackexchange.com/q/2447) of receiving input and providing output.
You may use any [programming language](http://meta.codegolf.stackexchange.com/q/2028), but note that [these loopholes](http://meta.codegolf.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default) are forbidden by default.
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest valid answer – measured in *bytes* – wins.
## Test Cases
There are only 8 possible inputs you need to handle, so there is no excuse for not testing your code on all of them:
```
N /   -->   W
N \   -->   E
E /   -->   S
E \   -->   N
S /   -->   E
S \   -->   W
W /   -->   N
W \   -->   S
```
  
[Answer]
# Python, ~~40~~ 38 bytes
-2 bytes thanks to @MitchSchwartz `(ord(d)+ord(m))%8` -> `ord(d)+ord(m)&7`
```
lambda d,m:' NESSWNW'[ord(d)+ord(m)&7]
```
plain lookup of answer in a list (AKA string) indexed by the smallest mod of the sum of ordinals that works.
Test cases are on [**ideone**](http://ideone.com/mPGH1A)
[Answer]
# Python 2, 40 bytes
```
lambda c,m,k="NWES":k[k.find(c)^(m>k)+1]
```
Sp3000 saved one byte (`.index` → `.find`).
## Explanation
We want to map the directions like so:
```
       \
  N ⇄⇄⇄⇄⇄⇄⇄ E
  ⇅         ⇅
  ⇅         ⇅
/ ⇅         ⇅ /
  ⇅         ⇅
  ⇅         ⇅
  W ⇄⇄⇄⇄⇄⇄⇄ S
       \
```
We can assign the directions 2-bit codes, and view both flips as XOR-ing the first and second bits:
```
         xor 2
     0 0 ⇄⇄⇄⇄⇄ 1 0
      ⇅         ⇅
      ⇅         ⇅
xor 1 ⇅         ⇅ xor 1
      ⇅         ⇅
      ⇅         ⇅
     0 1 ⇄⇄⇄⇄⇄ 1 1
         xor 2
```
The mapping between bit strings and directions happens using the string `k`. Now we just need to map mirror characters `'/'` and `'\\'` to the values `1` and `2`. Since `'/' < '\\'`, we could naïvely use `(m>'/')+1` as a formula. But wait! Lexicographically,
```
'/' < 'NWES' < '\\'
```
and we have `'NWES'` nicely assigned to `k`! So we can use `(m>k)+1` instead.
[Answer]
# CJam, 14 bytes
(@MartinEnder ported my [Python answer](https://codegolf.stackexchange.com/a/92023/53748))
```
l1b" NESSWNW"=
```
How?
```
l1b" NESSWNW"= -
l              - read input
 1b            - cast characters as base 1 digits
   " NESSWNW"  - the string " NESSWNW"
             = - modulo index into the string
```
Tests are on [**aditsu**](http://cjam.aditsu.net/#code=%7B%0A%0Al1b%22%20NESSWNW%22%3D%0A%0AoNo%7D8%2A&input=N%5C%0AN%2F%0AE%5C%0AE%2F%0AS%5C%0AS%2F%0AW%5C%0AW%2F)
[Answer]
## Javascript (ES6), ~~50~~ ~~41~~ ~~40~~ 37 bytes
```
d=>m=>(S="NWES")[S.search(d)^-~(m>S)]
```
*Saved 3 more bytes by using comparison, thanks to Lynn's answer*
### Usage
```
let f =
d=>m=>(S="NWES")[S.search(d)^-~(m>S)]
console.log(f("N")("/"));  //   -->   W
console.log(f("N")("\\")); //   -->   E
console.log(f("E")("/"));  //   -->   S
console.log(f("E")("\\")); //   -->   N
console.log(f("S")("/"));  //   -->   E
console.log(f("S")("\\")); //   -->   W
console.log(f("W")("/"));  //   -->   N
console.log(f("W")("\\")); //   -->   S
```
[Answer]
# [MATL](http://github.com/lmendo/MATL), ~~19~~ 17 bytes
```
'NWSE'jy&mjy+Eq-)
```
[Try it online!](http://matl.tryitonline.net/#code=J05XU0UnankmbWp5K0VxLSk&input=Vwov) Or [verify the eight cases](http://matl.tryitonline.net/#code=ODoiCidOV1NFJ2p5Jm1qeStFcS0p&input=TgovCk4KXApFCi8KRQpcClMKLwpTClwKVwovClcKXA).
### Explanation
```
'NWSE'    % Push this string
j         % Take first input, say 'W'. Stack contains: 'NWSE', 'W'
y         % Duplicate from below. Stack: 'NWSE', 'W', 'NWSE'
&m        % Index of membership. Stack: 'NWSE', 2
j         % Take second input, say '/'. Stack: 'NWSE', 2, '/'
y         % Duplicate from below. Stack: 'NWSE', 2, '/', 2
+         % Add (char '/' is converted to code point). Stack: 'NWSE', 2, 49 
Eq        % Multiply by 2, subtract 1. Stack: 'NWSE', 2, 97
-         % Subtract. Stack: 'NWSE', -95
)         % Apply -95 as (modular, 1-based) index into 'NWSE'. Stack: 'N'
          % Implicitly display
```
[Answer]
# Pyth, ~~17~~ ~~16~~ 15 bytes
*Thanks to @Jakube and @Maltysen for -1 byte each*
```
@J"NWES"xxJQh>E
```
A program that takes input of two newline-separated quoted strings, first the direction and then the mirror, and prints the result.
This is a port of @Lynn's Python [answer](https://codegolf.stackexchange.com/a/92014/55526).
[Try it online](https://pyth.herokuapp.com/?code=%40J%22NWES%22xxJQh%3EE&input=%22E%22%0A%22%5C%5C%22&test_suite=1&test_suite_input=%22N%22%0A%22%2F%22%0A%22N%22%0A%22%5C%5C%22%0A%22E%22%0A%22%2F%22%0A%22E%22%0A%22%5C%5C%22%0A%22S%22%0A%22%2F%22%0A%22S%22%0A%22%5C%5C%22%0A%22W%22%0A%22%2F%22%0A%22W%22%0A%22%5C%5C%22&debug=0&input_size=2)
**How it works**
```
@J"NWES"xxJQh>E  Program. Inputs: Q, E
 J"NWES"         J="NWES". Yield J
         xJQ     J.index(Q)
             >E  E>Q, lexographically (implicit input fill)
            h    +1
        x        Bitwise XOR of the above two
@                Index into J with the above
                 Implicitly print
```
[Answer]
# [05AB1E](http://github.com/Adriandmen/05AB1E), 14 bytes
```
‘€Ã‘DIkI'/kÌ^è
‘€Ã‘             # from string "NEWS"
             è   # get element at index
    DIk          # index of 1st input in string "NEWS"
            ^    # XOR
       I'/k      # index of 2nd input in string "/"
           Ì     # +2               
```
[Try it online!](http://05ab1e.tryitonline.net/#code=4oCY4oKsw4PigJhESWtJJy9rw4xew6g&input=Tgov)
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~14 13~~ 12 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
(a port of my [Python answer](https://codegolf.stackexchange.com/a/92023/53748))  
-1 byte thanks to @MartinEnder (add a space to end of the string and remove need for modulo 8)  
-1 byte thanks to @LuisMendo (take a single string argument rather than two)
```
OSị“NESSWNW 
```
How?
```
OSị“NESSWNW  - takes a single argument "dm" (direction and mirror), in either order.
                   strings and lists are equivalent in Jelly
 O            - ordinal: [ord(d),ord(m)]
  S           - sum: ord(d)+ord(m)
    “NESSWNW  - string: "NESSWNW "
   ị          - fetch modulo index (the string is 8 long and 1-based)
```
Test it on [**TryItOnline**](http://jelly.tryitonline.net/#code=T1Phu4vigJxORVNTV05XIA&input=&args=Ik4vIg)
[Answer]
# Java 7, ~~71~~ ~~70~~ 68 bytes
```
char c(int d,int m){return"NEWS".charAt("NEWS".indexOf(d)^-~(m%2));}
```
Too bad the `charAt` and `indexOf` takes up so much bytes..
**Ungolfed & all test cases:**
[Try it here.](https://ideone.com/dhykEw)
```
class M{
  static char c(int d, int m) {
    return "NEWS".charAt("NEWS".indexOf(d) ^ -~(m%2));
  }
  public static void main(String[] a){
    System.out.print(c('N', '/') + " ");
    System.out.print(c('N', '\\') + " ");
    System.out.print(c('E', '/') + " ");
    System.out.print(c('E', '\\') + " ");
    System.out.print(c('S', '/') + " ");
    System.out.print(c('S', '\\') + " ");
    System.out.print(c('W', '/') + " ");
    System.out.print(c('W', '\\') + " ");
  }
}
```
**Output:**
```
W E S N E W N S
```
[Answer]
# Python, ~~63~~ ~~61~~ 59 bytes
```
lambda d,m,x='NESW'*2:x[x.find(d)+2*(m=='/\\'[d in'NS'])-1]
```
Pretty simple. Can definitely be golfed more. Decides whether to add 1 or -1 to the input's index in `'NESW'`.
This is a lambda expression; to use it, prefix it with `f=`.
[Ideone it!](http://ideone.com/jIBN2i)
[Answer]
# Java 8, ~~62~~ ~~58~~ 56 bytes
```
(d,m)->"SEWN".charAt("NWES".indexOf(d)^m.indexOf(47)+2);
```
# Ungolfed test program
```
import java.util.function.BiFunction;
public class Mirror {
public static void main(String[] args) {
    BiFunction<String, String, Character> function = (d,m)->"SEWN".charAt("NWES".indexOf(d)^m.indexOf(47)+2);
    System.out.println(function.apply("N", "/")); //W
    System.out.println(function.apply("N", "\\")); //E
    System.out.println(function.apply("W", "/")); //N
    System.out.println(function.apply("W", "\\")); //S
    System.out.println(function.apply("E", "/")); //S
    System.out.println(function.apply("E", "\\")); //N
    System.out.println(function.apply("S", "/")); //E
    System.out.println(function.apply("S", "\\")); //W
}
}
```
[Answer]
## PowerShell v2+, 34 bytes
```
param($a,$b)"xNESSWNW"[(+$a+$b)%8]
```
Takes input as two explicit `char`s, outputs a `char`.
This works as follows: If we sort the output, we want `S` `/` to somehow equal the same as `N` `\`, `W` `/` to equal `E` `\`, etc. Or, at least, produce numbers that are "close enough" yet still distinct. If we look at the ASCII values, we get a table like the below:
```
In1   In2       Res.    Sum
S 83  / 47  --> E 69 -> 130
N 78  \ 92  --> E 69 -> 170
W 87  / 47  --> N 78 -> 134
E 69  \ 92  --> N 78 -> 161
W 87  \ 92  --> S 83 -> 179
E 69  / 47  --> S 83 -> 116
N 78  / 47  --> W 87 -> 125
S 83  \ 92  --> W 87 -> 175
```
Running a quick brute-forcer on the summations column (derived from summing the ASCII code points of the inputs) shows that if we take the sums modulo `8`, we get the following `2 2 | 6 1 | 3 4 | 5 7`. That's evidenced in the string `"xNESSWNW"`, as `E` is at index `2`, `N` is at `6` and `1`, and so on.
So, we just need to sum the inputs (implicitly casting from `char` to `int32` along the way), take that `%8`, and use that to index into our string.
### Test Cases
```
PS C:\Tools\Scripts\golfing> ('N','/'),('N','\'),('E','/'),('E','\'),('S','/'),('S','\'),('W','/'),('W','\')|%{"$($_[0]) $($_[1]) --> "+(.\mirror-mirror-in-the-code.ps1 ([char]$_[0]) ([char]$_[1]))}
N / --> W
N \ --> E
E / --> S
E \ --> N
S / --> E
S \ --> W
W / --> N
W \ --> S
```
[Answer]
## Batch, 111 bytes
```
:goto %1
:W/
:E\
@echo N
@exit/b
:S/
:N\
@echo E
@exit/b
:E/
:W\
@echo S
@exit/b
:N/
:S\
@echo W
```
Accepts e.g. `W/` as a two-character string command line parameter. The `\` and `/` make looping awkward; it would have taken 124 bytes.
[Answer]
# Octave, 30 bytes
Used the same order of arguments as Jonathan Allan.
Takes the input as two-character string `'W\'`.
```
@(x)['NESSWNW'](mod(sum(x),8))
```
Try it [online](https://ideone.com/zzyxeb).
[Answer]
# C, 44, 35, 34 bytes
```
f(a,b){return"NWES"[a&a/2&3^b&3];}
```
It requires two characters as two variables. It takes both lower and upper case. It uses a lot of bit manipulation. The fragment `a&a/2` results in a value that has unique values for the lower two bits, `&3` cuts off all higher bits. This used as an index into the string "NWES" for the `\` mirror. Luckily, the lower two bits of the ASCII characters `\` and `/` are 00 and 11 respectively, which is perfect to XOR with the aforementioned index to get the correct direction for the `/` mirror.
[Answer]
# [CJam](http://sourceforge.net/projects/cjam/), 17 bytes
```
r"SWEN"_e!r'/#=er
```
Input is space-separated.
[Try it online!](http://cjam.tryitonline.net/#code=ewoKciJTV0VOIl9lIXInLyM9ZXIKCm59OCo&input=TiBcCk4gLwpFIFwKRSAvClMgXApTIC8KVyBcClcgLw) (As a linefeed-separated test suite.)
This is the solution I found before posting the challenge. Not as short as Jonathan's cyclic indexing, but I thought this approach is quite interesting (and novel).
### Explanation
The goal is use transliteration (i.e. using a character-to-character mapping) to replace the input character with the output character. To do this, we need to select the correct map based on whether the mirror is `/` or `\`. We'll map from the `SWEN` list to another one which we'll select conditionally. If the input list is `SWEN`, the two output maps need to be the following:
```
in  SWEN
/   ENSW
\   WSNE
```
Note that these are in sorted and reverse-sorted order (which is why we chose the seemingly random `SWEN` order as the input set). We could generate these by sorting the input list and the reversing the result if the input has `\`, but there's a better way:
```
r       e# Read incoming direction.
"SWEN"  e# Push input list for transliteration.
_e!     e# Duplicate and get all permutations. The way, `e!` is implemented, it
        e# always gives the permutations in sort order, regardless of the order
        e# of the input set. Specifically that means that "ENSW" will be first
        e# and "WSNE" will be last in this list.
r       e# Read the mirror.
'/#     e# Find the index of / in this string. If the mirror is '/', then this
        e# gives 0. Otherwise, this gives -1, indicating that '/' was not found.
=       e# Select the corresponding permutation. Indexing is zero-based and
        e# cyclic so that 0 (input '/') gives the first permutation "ENSW" and
        e# -1 (input '\') gives the last permutation "WSNE".
er      e# Perform the transliteration on the incoming direction.
        e# Printing is implicit.
```
[Answer]
# SED 48 (42 + 1 for -r) 43
Saved 5 thanks to Martin Ender♦ 
```
s,N/|S\\,W,;s,E/|W\\,S,;s,N.|S/,E,;s,..,N,
```
Takes input as a two character string.
[Answer]
# Mathematica, 98 bytes
```
If[#2=="/",{"S",,,,,,,,,"W",,,,,"E",,,,"N"},{"N",,,,,,,,,"E",,,,,"W",,,,"S"}][[LetterNumber@#-4]]&
```
Anonymous function. Takes two strings as input and returns a string as output.
[Answer]
## C, 81 bytes
```
f(char*a){return a!="N/"&a!="S\\"?a!="N\\"&a!="S/"?a!="W\\"&a!="E/"?78:83:69:87;}
```
### Usage
```
main()
{
    printf("N/ \t %c\n",f("N/"));
    printf("N\\\t %c\n",f("N\\"));
    printf("E/ \t %c\n",f("E/"));
    printf("E\\\t %c\n",f("E\\"));
    printf("S/ \t %c\n",f("S/"));
    printf("S\\\t %c\n",f("S\\"));
    printf("W/ \t %c\n",f("W/"));
    printf("W\\\t %c\n",f("W\\"));
}
```
**Output:**
```
N/      : W  
N\      : E  
E/      : S  
E\      : N  
S/      : E  
S\      : W  
W/      : N  
W\      : S  
```
[Answer]
# Pyth, 13 bytes
```
@."EW¹0`Y"sCM    
```
[Test suite](https://pyth.herokuapp.com/?code=%40.%22EW%C2%B90%60Y%22sCM&test_suite=1&test_suite_input=%22N%2F%22%0A%22N%5C%5C%22%0A%22E%2F%22%0A%22E%5C%5C%22%0A%22S%2F%22%0A%22S%5C%5C%22%0A%22W%2F%22%0A%22W%5C%5C%22&debug=0)
Sum the code points, modular index, compressed string.
[Answer]
# TI-Basic, 40 bytes
Hardcodes the inputs. Boring, but the shortest way.
```
sub("NEWS",1+int(inString("E/W\N\S/N/S\E\W/",Ans)/4),1
```
]