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 and use any of the our standard methods of receiving input and providing output.
You may use any programming language, but note that these loopholes are forbidden by default.
This is 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
\
. If your answer is a function submission that takes a string, then of course you'll need\\
in the source code to call it correctly, but if you're reading your input from standard input, for instance, then it should be a single\
. In other words, if you call your language's respective string-length function on the input, the result should always be the same, regardless of whether the input contains/
or\
. \$\endgroup\$readline()
can handle it. \$\endgroup\$