Created
May 17, 2016 22:09
-
-
Save sklivvz/e348b3f28d50e3c197a981681c59167a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Main() | |
{ | |
var m = new int[] { 0, 1, 0, -1, 0 }; | |
var inputs = @"5 5 | |
1 2 N | |
LMLMLMLMM | |
3 3 E | |
MMRMMRMRRM".Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); | |
for (int i = 1; i < inputs.Length; i += 2) | |
{ | |
var start = inputs[i].Split(" ".ToCharArray()); | |
int x, y, o; | |
if (start.Length != 3 || !int.TryParse(start[0], out x) || !int.TryParse((start[1]), out y) || (o = "NESW".IndexOf(start[2])) == -1) goto skip; | |
foreach (var c in inputs[i+1]) | |
switch (c) | |
{ | |
case 'L': o = --o & 3; break; | |
case 'R': o = ++o & 3; break; | |
case 'M': x += m[o]; y += m[o + 1]; break; | |
default: goto skip; | |
} | |
Console.WriteLine($"{x} {y} {"NESW"[o]}"); | |
skip:; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment