-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1-1.linq
27 lines (24 loc) · 985 Bytes
/
1-1.linq
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<Query Kind="Program" />
void Main()
{
Directory.SetCurrentDirectory(Path.GetDirectoryName(Util.CurrentQueryPath));
string inputLine = File.ReadAllLines("1.txt").First();
string[] inputs = inputLine.Split(new[] { ", "}, StringSplitOptions.None);
char[] directions = new[] { 'N', 'E', 'S', 'W' };
int directionIndex = 0;
int x = 0;
int y = 0;
foreach (var input in inputs)
{
if (input[0] == 'L') directionIndex--;
else directionIndex++;
if (directionIndex == -1) directionIndex = 3;
else if (directionIndex == 4) directionIndex = 0;
int steps = int.Parse(input.Substring(1, input.Length - 1));
if (directions[directionIndex] == 'N') y -= steps;
else if (directions[directionIndex] == 'E') x += steps;
else if (directions[directionIndex] == 'S') y += steps;
else if (directions[directionIndex] == 'W') x -= steps;
}
Console.WriteLine(Math.Abs(x) + Math.Abs(y));
}