|
|
@@ -9,10 +9,13 @@ namespace D6._2
|
|
|
{
|
|
|
static void Main(string[] args)
|
|
|
{
|
|
|
- if (args.Length < 1) return;
|
|
|
+ if (args.Length < 3) return;
|
|
|
if (File.Exists(args[0]) == false) return;
|
|
|
+ if (int.TryParse(args[1], out int size) == false) return;
|
|
|
+ if (int.TryParse(args[2], out int ceil) == false) return;
|
|
|
|
|
|
var coordinates = new List<(uint x, uint y)>();
|
|
|
+
|
|
|
var file = File.OpenText(args[0]);
|
|
|
|
|
|
do
|
|
|
@@ -26,25 +29,25 @@ namespace D6._2
|
|
|
|
|
|
int area = 0;
|
|
|
|
|
|
- for (uint x = 0; x < 500; x++)
|
|
|
+ for (uint x = 0; x < size; x++)
|
|
|
{
|
|
|
- for (uint y = 0; y < 500; y++)
|
|
|
+ for (uint y = 0; y < size; y++)
|
|
|
{
|
|
|
- var total = GetTotalDistance(coordinates, x, y);
|
|
|
- if (total < 10000) area++;
|
|
|
+ var total = GetTotalDistance(coordinates, (x, y));
|
|
|
+ if (total < ceil) area++;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
Console.WriteLine($"Answer : {area}");
|
|
|
}
|
|
|
|
|
|
- private static int GetTotalDistance(List<(uint x, uint y)> coordinates, uint x, uint y)
|
|
|
+ private static int GetTotalDistance(List<(uint x, uint y)> coordinates, (uint x, uint y) point)
|
|
|
{
|
|
|
int total = 0;
|
|
|
for (int i = 0; i < coordinates.Count; i++)
|
|
|
{
|
|
|
- var coord = coordinates[i];
|
|
|
- var manhattan = Math.Abs((int)x - (int)coord.x) + Math.Abs((int)y - (int)coord.y);
|
|
|
+ var (x, y) = coordinates[i];
|
|
|
+ var manhattan = Math.Abs((int)point.x - (int)x) + Math.Abs((int)point.y - (int)y);
|
|
|
total += manhattan;
|
|
|
}
|
|
|
return total;
|