bastien.monsarrat 7 年 前
コミット
0bf91d6d7d
2 ファイル変更12 行追加9 行削除
  1. 11 8
      D6.2/Program.cs
  2. 1 1
      D6.2/Properties/launchSettings.json

+ 11 - 8
D6.2/Program.cs

@@ -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;

+ 1 - 1
D6.2/Properties/launchSettings.json

@@ -2,7 +2,7 @@
   "profiles": {
     "D06.2": {
       "commandName": "Project",
-      "commandLineArgs": "\"D:\\adv\\Adv2018\\D6.2\\input.txt\""
+      "commandLineArgs": "\"D:\\adv\\Adv2018\\D6.2\\input.txt\" 500 10000"
     }
   }
 }