Forráskód Böngészése

D20.2 is KO but I dont know why

bastien.monsarrat 6 éve
szülő
commit
f96273c8f1
3 módosított fájl, 9 hozzáadás és 10 törlés
  1. 2 2
      Adv2018.sln
  2. 0 0
      D20.1/D20.1and2.csproj
  3. 7 8
      D20.1/Program.cs

+ 2 - 2
Adv2018.sln

@@ -81,9 +81,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "D19.1", "D19.1\D19.1.csproj
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D17.Bonus", "D17.Bonus\D17.Bonus.csproj", "{B2F8CC8B-1A12-4778-BE51-14B32EBB2B89}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D19.2", "D19.2\D19.2.csproj", "{F1899F43-F7D2-493D-B23A-D07AFEC93495}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "D19.2", "D19.2\D19.2.csproj", "{F1899F43-F7D2-493D-B23A-D07AFEC93495}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D20.1", "D20.1\D20.1.csproj", "{BA7DC3A0-9406-46BD-8B2A-CAE906EC5F22}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "D20.1and2", "D20.1\D20.1and2.csproj", "{BA7DC3A0-9406-46BD-8B2A-CAE906EC5F22}"
 EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution

+ 0 - 0
D20.1/D20.1.csproj → D20.1/D20.1and2.csproj


+ 7 - 8
D20.1/Program.cs

@@ -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]);
             }
         }
     }