bastien.monsarrat 7 anni fa
parent
commit
73fd2fba3e
5 ha cambiato i file con 123 aggiunte e 6 eliminazioni
  1. 6 0
      Adv2018.sln
  2. 8 6
      D10.1/Program.cs
  3. 13 0
      D10.2/D10.2.csproj
  4. 88 0
      D10.2/Program.cs
  5. 8 0
      D10.2/Properties/launchSettings.json

+ 6 - 0
Adv2018.sln

@@ -43,6 +43,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D09.2", "D9.2\D09.2.csproj"
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D10.1", "D10.1\D10.1.csproj", "{B50DA992-9316-4573-B0D2-5A4352EB3C4A}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D10.2", "D10.2\D10.2.csproj", "{9A5878B7-51D8-432D-AD25-DF2DC5EEDDAF}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -129,6 +131,10 @@ Global
 		{B50DA992-9316-4573-B0D2-5A4352EB3C4A}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{B50DA992-9316-4573-B0D2-5A4352EB3C4A}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{B50DA992-9316-4573-B0D2-5A4352EB3C4A}.Release|Any CPU.Build.0 = Release|Any CPU
+		{9A5878B7-51D8-432D-AD25-DF2DC5EEDDAF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{9A5878B7-51D8-432D-AD25-DF2DC5EEDDAF}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{9A5878B7-51D8-432D-AD25-DF2DC5EEDDAF}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{9A5878B7-51D8-432D-AD25-DF2DC5EEDDAF}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

+ 8 - 6
D10.1/Program.cs

@@ -68,12 +68,9 @@ namespace D10._1
 
         static bool isOk(Map map)
         {
-            var c = 0;
             for (var i = 0; i < map.Count; ++i)
-            {
-                if (isIsolated(map, i)) c++;
-            }
-            return c < 100;
+                if (isIsolated(map, i)) return false;
+            return true;
         }
 
         static bool isIsolated(Map map, int current)
@@ -85,9 +82,14 @@ namespace D10._1
                     continue;
 
                 if (star.x == currentStar.x && (star.y == currentStar.y + 1 || star.y == currentStar.y - 1))
-                    return false; 
+                    return false;
                 if (star.y == currentStar.y && (star.x == currentStar.x + 1 || star.x == currentStar.x - 1))
                     return false;
+
+                if ((star.x == currentStar.x + 1 || star.x == currentStar.x - 1) && (star.y == currentStar.y + 1 || star.y == currentStar.y - 1))
+                    return false;
+                if ((star.y == currentStar.y + 1 || star.y == currentStar.y - 1) && (star.x == currentStar.x + 1 || star.x == currentStar.x - 1))
+                    return false;
             }
 
             return true;

+ 13 - 0
D10.2/D10.2.csproj

@@ -0,0 +1,13 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <OutputType>Exe</OutputType>
+    <TargetFramework>netcoreapp2.1</TargetFramework>
+    <RootNamespace>D10._2</RootNamespace>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <PackageReference Include="System.Drawing.Common" Version="4.5.1" />
+  </ItemGroup>
+
+</Project>

+ 88 - 0
D10.2/Program.cs

@@ -0,0 +1,88 @@
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.IO;
+using System.Linq;
+using System.Text.RegularExpressions;
+
+namespace D10._2
+{
+    class Map : List<(int x, int y, int vx, int vy)> { }
+
+    class Program
+    {
+        static void Main(string[] args)
+        {
+            if (args.Length < 1) return;
+            if (File.Exists(args[0]) == false) return;
+            var file = File.OpenText(args[0]);
+
+            var r = new Regex(@"position=<\s*(?<posx>-?\d+),\s*(?<posy>-?\d+)> velocity=<\s*(?<vx>-?\d+),\s*(?<vy>-?\d+)>");
+
+            var map = new Map();
+
+            do
+            {
+                var line = file.ReadLine();
+                if (line == null) break;
+
+                var result = r.Match(line);
+
+                map.Add((
+                    int.Parse(result.Groups["posx"].Value),
+                    int.Parse(result.Groups["posy"].Value),
+                    int.Parse(result.Groups["vx"].Value),
+                    int.Parse(result.Groups["vy"].Value)
+                ));
+
+            } while (true);
+
+            int tt = 0;
+            do
+            {
+                for (var i = 0; i < map.Count; ++i)
+                {
+                    var star = map[i];
+
+                    star.x += star.vx;
+                    star.y += star.vy;
+
+                    map[i] = star;
+                }
+
+                tt++;
+            } while (isOk(map) == false);
+
+            Console.WriteLine($"Answer is : {tt}s");
+        }
+
+        static bool isOk(Map map)
+        {
+            for (var i = 0; i < map.Count; ++i)
+                if (isIsolated(map, i)) return false;
+            return true;
+        }
+
+        static bool isIsolated(Map map, int current)
+        {
+            var currentStar = map[current];
+            foreach (var star in map)
+            {
+                if (star.x == currentStar.x && star.y == currentStar.y)
+                    continue;
+
+                if (star.x == currentStar.x && (star.y == currentStar.y + 1 || star.y == currentStar.y - 1))
+                    return false;
+                if (star.y == currentStar.y && (star.x == currentStar.x + 1 || star.x == currentStar.x - 1))
+                    return false;
+
+                if ((star.x == currentStar.x + 1 || star.x == currentStar.x - 1) && (star.y == currentStar.y + 1 || star.y == currentStar.y - 1))
+                    return false;
+                if ((star.y == currentStar.y + 1 || star.y == currentStar.y - 1) && (star.x == currentStar.x + 1 || star.x == currentStar.x - 1))
+                    return false;
+            }
+
+            return true;
+        }
+    }
+}

+ 8 - 0
D10.2/Properties/launchSettings.json

@@ -0,0 +1,8 @@
+{
+  "profiles": {
+    "D10.2": {
+      "commandName": "Project",
+      "commandLineArgs": "\"D:\\adv\\Adv2018\\D10.1\\input.txt\" "
+    }
+  }
+}