Aircraft Marshalling School Given a string representing a series of aircraft marshalling hand signals, write a function or program to calculate the final position of an aircraft following these signals.

N.B.: Co-ordinates in this challenge are represented as a pair of Cartesian co-ordinates, plus a compass direction heading: (x, y, h) where x is the x-coordinate, y is the y-coordinate, and h is one of N, E, S, or W.

You start with an aircraft at (0, 0, N) on an imaginary grid, with engines off. Your input is a string containing comma-delimeted pairs of characters, where each pair represents one marshalling signal. You must follow each marshalling signal in turn, and output the co-ordinates in (x, y, h) form of the aircraft's final position.

If a signal requires your aircraft to move, assume it moves one unit in the required direction for each signal of that type that it receives. If a signal requires your aircraft to turn, assume it turns 90 degrees in the required direction for each signal of that type that it receives.

An aircraft cannot move if its engines are off. If your aircraft's engines are off and you receive a movement/turn signal, do not apply the movement/turn.

Signals

Each marshalling signal is represented by one pair of characters. The first of the pair represents the position of the marshaller's left arm, from the aircraft's point of view, and the second the right arm from the same POV. This handy chart of signals may help.

o/  —  START ENGINES (no movement, no turn)
-/  —  CUT ENGINES   (no movement, no turn)
-~  —  TURN LEFT     (no movement, left turn)
~-  —  TURN RIGHT    (no movement, right turn)
~~  —  COME FORWARD  (forward movement, no turn)
::  —  MOVE BACK     (backward movement, no turn)
/\  —  NORMAL STOP   (no movement, no turn)


This is not the complete list of marshalling signals, but it's all you're required to support.

Input

Input is a comma-delimeted string containing pairs of characters. This string will always be valid - you do not have to validate the input.

Output

Output is a set of co-ordinates as described above. You can return this in any convenient format - if your language supports multiple return values, you may use that; alternatively, you can use a string (the brackets surrounding the co-ordinates are non-compulsory), array, tuple, list, or whatever else you find convenient. The only rule is that it must contain x, y, and h values, in that order.

Test Cases

Input  —  Output
o/,~~,~~,~-,::  —  (-1, 2, E)
::,~-,o/,/\,~~,-~,~~,~~,~~  —  (-3, 1, W)
o/,::,-/,~~,o/,~-,~~,~~,~-  —  (2, -1, S)
o/,~-,~-,::,::,~-,~~,-~  —  (-1, 2, S)
~-,~-,o/,::,::,-/,~~,-~  —  (0, -2, N)
Java 8, 505 bytes
Golfed (with help from @masterX244 for shaving a big chunk off)
class f{static boolean T(String u,String v){return u.equals(v);}public static void main(String[]a){java.util.Scanner q=new java.util.Scanner(System.in);String s=q.nextLine();int x=0;int y=0;int d=0;int[][]v={{0,1},{-1,0},{0,-1},{1,0}};int b=1;for(String r:s.split(&quot;,&quot;)){if(T(r,&quot;o/&quot;)||T(r,&quot;-/&quot;))b=~1;if(b&lt;0){if(T(r,‌​&quot;~-&quot;))d=(d+3)%4;if(T‌​(r,&quot;-~&quot;))d=(d+1)%4;i‌​f(T(r,&quot;~~&quot;)){x+=v[d]‌​[0];y+=v[d][1];}if(T‌​(r,&quot;::&quot;)){x-=v[d][0]‌​;y-=v[d][1];}}}Syste‌​m.out.println(&quot;(&quot;+x+‌​&quot;,&quot;+y+&quot;,&quot;+&quot;NWSE&quot;.cha‌​rAt(d)+&quot;)&quot;);}}

More readable
class f {
    static boolean T(String u,String v){return u.equals(v);}
    public static void main(String[] a) {
        java.util.Scanner q=new java.util.Scanner(System.in);
        String s=q.nextLine();
        int x=0;
        int y=0;
        int d=0;
        int[][] val = {
                {0,1},  // N
                {-1,0}, // W
                {0,-1}, // S
                {1,0}   // E
        };
        int b=1;
        for (String r: s.split(&quot;,&quot;)) {
            // toggle b if either start or stop engine
            if(T(r,&quot;o/&quot;) || T(r,&quot;-/&quot;))
                b=~1;
            if(b&lt;0){
                // right
                if(T(r,&quot;~-&quot;)) d=(d+3)%4;
                // left
                if(T(r,&quot;-~&quot;)) d=(d+1)%4;
                // come forward
                if(T(r,&quot;~~&quot;)) {
                    x+=val[d][0];
                    y+=val[d][1];
                }
                // move back
                if(T(r,&quot;::&quot;)) {
                    x-=val[d][0];
                    y-=val[d][1];
                }
            }
        }
        System.out.print(&quot;(&quot;+x+&quot;,&quot;+y+&quot;,&quot;+&quot;NWSE&quot;.charAt(d)+&quot;)&quot;);
    }
}