|
|
@@ -141,24 +141,25 @@ namespace D20._1
|
|
|
Console.WriteLine(sw.ElapsedMilliseconds);
|
|
|
|
|
|
Dictionary<(int x, int y), int> positions = new Dictionary<(int x, int y), int>();
|
|
|
+ positions.Add((0, 0), 0);
|
|
|
+
|
|
|
foreach (var path in root.Possibilities)
|
|
|
{
|
|
|
TestResult(path, positions);
|
|
|
}
|
|
|
|
|
|
int max = positions.Max(p => p.Value);
|
|
|
- Console.WriteLine(max);
|
|
|
+ int d = positions.Count(p => p.Value >= 1000);
|
|
|
+ Console.WriteLine($"Ex 1 : {max}\nEx 2 ; {d}");
|
|
|
}
|
|
|
|
|
|
private static void TestResult(string str, Dictionary<(int x, int y), int> positions)
|
|
|
{
|
|
|
- (int x, int y) pos = (0, 0);
|
|
|
int dist = 0;
|
|
|
+ (int x, int y) pos = (0, 0);
|
|
|
|
|
|
- positions.TryAdd(pos, 0);
|
|
|
foreach (var c in str)
|
|
|
{
|
|
|
- var bpos = pos;
|
|
|
switch (c)
|
|
|
{
|
|
|
case 'N': pos.y -= 1; break;
|
|
|
@@ -167,10 +168,8 @@ namespace D20._1
|
|
|
case 'E': pos.x += 1; break;
|
|
|
}
|
|
|
|
|
|
- dist++;
|
|
|
- if (positions.TryAdd(pos, dist) == false)
|
|
|
- dist = Math.Min(dist + 1, positions[pos]);
|
|
|
- positions[pos] = dist;
|
|
|
+ if (positions.TryAdd(pos, dist + 1)) dist = dist + 1;
|
|
|
+ else dist = Math.Min(dist + 1, positions[pos]);
|
|
|
}
|
|
|
}
|
|
|
}
|