bastien.monsarrat 6 years ago
parent
commit
dfd3f9c9ea

+ 20 - 8
Adv2015.sln

@@ -49,21 +49,25 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "D12.2", "D12.2\D12.2.csproj
 EndProject
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "D13.1", "D13.1\D13.1.csproj", "{38FBCA6A-29F0-4FC8-B0DB-616DDC27E459}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D13.2", "D13.2\D13.2.csproj", "{46445805-4831-436D-A531-9D973306DD2E}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "D13.2", "D13.2\D13.2.csproj", "{46445805-4831-436D-A531-9D973306DD2E}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D14.1", "D14.1\D14.1.csproj", "{276D6A7D-A62C-48C9-B841-1AFFB11E93B0}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "D14.1", "D14.1\D14.1.csproj", "{276D6A7D-A62C-48C9-B841-1AFFB11E93B0}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D14.2", "D14.2\D14.2.csproj", "{D55FCBDF-60C8-4DCE-B788-4799FE19CAB3}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "D14.2", "D14.2\D14.2.csproj", "{D55FCBDF-60C8-4DCE-B788-4799FE19CAB3}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D15.1", "D15.1\D15.1.csproj", "{03B01AF1-879A-46D4-BDD6-12F1443476FE}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "D15.1", "D15.1\D15.1.csproj", "{03B01AF1-879A-46D4-BDD6-12F1443476FE}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D15.2", "D15.2\D15.2.csproj", "{7AED7764-630F-44E6-850C-23093BA54E7F}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "D15.2", "D15.2\D15.2.csproj", "{7AED7764-630F-44E6-850C-23093BA54E7F}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D16.1", "D16.1\D16.1.csproj", "{12B73565-BDE7-4AC8-B6B5-4CC777804073}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "D16.1", "D16.1\D16.1.csproj", "{12B73565-BDE7-4AC8-B6B5-4CC777804073}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D16.2", "D16.2\D16.2.csproj", "{E77FF61C-90C8-4C1C-A458-CA0479C5BAA6}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "D16.2", "D16.2\D16.2.csproj", "{E77FF61C-90C8-4C1C-A458-CA0479C5BAA6}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D17", "D17.1\D17.csproj", "{513BD630-6A66-487D-8199-68CE213DECF4}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "D17", "D17.1\D17.csproj", "{513BD630-6A66-487D-8199-68CE213DECF4}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "D18.1", "D18.1\D18.1.csproj", "{90F84068-1388-4124-8ED5-DB658383D961}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D18.2", "D18.2\D18.2.csproj", "{BF47427D-176C-4059-9DEC-EA709E7F28A0}"
 EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -195,6 +199,14 @@ Global
 		{513BD630-6A66-487D-8199-68CE213DECF4}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{513BD630-6A66-487D-8199-68CE213DECF4}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{513BD630-6A66-487D-8199-68CE213DECF4}.Release|Any CPU.Build.0 = Release|Any CPU
+		{90F84068-1388-4124-8ED5-DB658383D961}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{90F84068-1388-4124-8ED5-DB658383D961}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{90F84068-1388-4124-8ED5-DB658383D961}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{90F84068-1388-4124-8ED5-DB658383D961}.Release|Any CPU.Build.0 = Release|Any CPU
+		{BF47427D-176C-4059-9DEC-EA709E7F28A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{BF47427D-176C-4059-9DEC-EA709E7F28A0}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{BF47427D-176C-4059-9DEC-EA709E7F28A0}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{BF47427D-176C-4059-9DEC-EA709E7F28A0}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

+ 9 - 0
D18.1/D18.1.csproj

@@ -0,0 +1,9 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <OutputType>Exe</OutputType>
+    <TargetFramework>netcoreapp2.1</TargetFramework>
+    <RootNamespace>D18._1</RootNamespace>
+  </PropertyGroup>
+
+</Project>

+ 91 - 0
D18.1/Program.cs

@@ -0,0 +1,91 @@
+using System;
+using System.IO;
+using System.Linq;
+using System.Text;
+
+namespace D18._1
+{
+    class Program
+    {
+        static void Main(string[] args)
+        {
+            const int len = 100;
+
+            string input = ParseFile(args[0]);
+
+            for (int i = 0; i < 100; ++i)
+                input = Step(len, input);
+
+            int litOn = input.Count(c => c == '#');
+
+            Console.WriteLine($"The answer is : {litOn}");
+        }
+
+        private static string ParseFile(string arg)
+        {
+            var sb = new StringBuilder();
+            using (var file = File.OpenText(arg))
+            {
+                while (true)
+                {
+                    var line = file.ReadLine();
+                    if (line == null) break;
+
+                    sb.Append(line);
+                }
+            }
+
+            string input = sb.ToString();
+            return input;
+        }
+
+        private static string Step(int len, string input)
+        {
+            int edgeDetector = 0;
+            int totalSize = len * len;
+            int lastLineDetector = len * (len - 1);
+            int lastColumn = len - 1;
+
+            var stepb = new StringBuilder();
+            for (int i = 0; i < totalSize; ++i)
+            {
+                char state = input[i];
+                char nstate = state;
+
+                int onNeighbors = DetectNeoghbors(len, input, edgeDetector, lastLineDetector, lastColumn, i);
+
+                if (state == '#')
+                {
+                    if (onNeighbors != 2 && onNeighbors != 3) nstate = '.';
+                }
+                else
+                {
+                    if (onNeighbors == 3) nstate = '#';
+                }
+
+                stepb.Append(nstate);
+
+                edgeDetector = edgeDetector == lastColumn ? 0 : edgeDetector + 1;
+            }
+
+            return stepb.ToString();
+        }
+
+        private static int DetectNeoghbors(int len, string input, int edgeDetector, int lastLineDetector, int lastColumn, int i)
+        {
+            int onNeighbors = 0;
+            bool onFirstLine = i < len;
+            bool onLastLine = i >= lastLineDetector;
+
+            if (edgeDetector > 0) onNeighbors += input[i - 1] == '#' ? 1 : 0;
+            if (edgeDetector < lastColumn) onNeighbors += input[i + 1] == '#' ? 1 : 0;
+            if (onFirstLine == false) onNeighbors += input[i - len] == '#' ? 1 : 0;
+            if (onLastLine == false) onNeighbors += input[i + len] == '#' ? 1 : 0;
+            if (onFirstLine == false && edgeDetector > 0) onNeighbors += input[i - len - 1] == '#' ? 1 : 0;
+            if (onFirstLine == false && edgeDetector < lastColumn) onNeighbors += input[i - len + 1] == '#' ? 1 : 0;
+            if (onLastLine == false && edgeDetector > 0) onNeighbors += input[i + len - 1] == '#' ? 1 : 0;
+            if (onLastLine == false && edgeDetector < lastColumn) onNeighbors += input[i + len + 1] == '#' ? 1 : 0;
+            return onNeighbors;
+        }
+    }
+}

+ 8 - 0
D18.1/Properties/launchSettings.json

@@ -0,0 +1,8 @@
+{
+  "profiles": {
+    "D18.1": {
+      "commandName": "Project",
+      "commandLineArgs": "\"..\\..\\..\\..\\D18.1\\input.txt\""
+    }
+  }
+}

+ 100 - 0
D18.1/input.txt

@@ -0,0 +1,100 @@
+####.#.##.###.#.#.##.#..###.#..#.#.#..##....#.###...##..###.##.#.#.#.##...##..#..#....#.#.##..#...##
+.##...##.##.######.#.#.##...#.#.#.#.#...#.##.#..#.#.####...#....#....###.#.#.#####....#.#.##.#.#.##.
+###.##..#..#####.......#.########...#.####.###....###.###...#...####.######.#..#####.#.###....####..
+....#..#..#....###.##.#.....##...#.###.#.#.#..#.#..##...#....#.##.###.#...######......#..#.#..####.#
+..###.####..#.#.#..##.#.#....#......#.##.##..##.#.....##.###.#..###...###.#.##..#.#..###....####.#.#
+#.#...#......####.#..##.####.#.#.#...##..###.##.#...#..#..###....#.#....#..##..#....##.....##.#...#.
+....##.#.#.#.##..##...##..##..#....#....###...####.###...##.#...#..#....##.....#..#.#####.###.###.##
+#...##..#.#..#....#..########.##....##..##.###..#.#..#..#.##.##.#..##..######....####..#####.#.###..
+.####...######.#..#.##.#.#..####...####.##.#.#......#...##....##..#...###..#.####......###......#.##
+.####.###..#..#####.##...###......#...###..#..##..#.#....##.##.#.##.###..#..#..###.#..#.#....####.##
+#..#..##.##.##.###.#.##.##.#.#.#....#....#.####.#.##...#####...###.#####.#.#.#....####..###..###..##
+#.##....#...########..##...#.#.##.......#.#..##...####...#.####.####..##...##.#....###.#.####...#.##
+#.#...##..#.##.##..##....#.....##.##.....#...###...#..#...####.##.####..#...##..##.##.##.##..##...##
+.#..###...#.#.....#######..##.###....##..#.##.#......###.##....#......###...#.##....#.....##......##
+..##....#.###...###..####.##..#..##.##......##.#.....#...#..#..##...###..#.####...#...#..##.#..##..#
+...#.#.#...#.#..#.##....##..#...#.##..#......#.#.....#####.##.#...#######.#.#..#.####..###.....###.#
+.#....#.#.##..####.#####..#.#######..#.##.###...##.##....##..###..#.##.###.......#....#..######.####
+#..#.##.##..#..#..##.####.#.#.#.#..#.##...#..######....#.##.#..##.##.######.###.###.###...#.....#.#.
+.#.......#...#.####.##...#####..##..#.#....##..#.#.#.####.#.##....#..##.##..#.###.....#.##.##.#.##.#
+#..##..##...#....#.##.#...#.#....#......####...##..#...##.##.#..#########..#..#.##.##..#.#.#######..
+#.......#####..###..######.#..##.#.#####..##...###...#.####.##...###..#.#.#####....#...#.##...#.#..#
+.##..#...#####.##.##......#...#.#.#.###.#.#.#...##.#..#....###.....#..#.#.###......#####.###.#..##.#
+.....###.#.#.#..##...#...###..#...#.#.##..###.##.#####.##..#.#.#.#.#####....#.#.#####...##.#..#.#.#.
+###...##.#..#.####..##.#..##.#.#.#...#.#..#..##..##..#.#.#.#.##...##..#..#.....#....#####.#.#.####.#
+....##....#.#.....#...###.#...##..##.##..#..###..##.###..#####..#...#####.##.#..#.#.#.###...####.###
+##.##.##.#...#..#...........##.##.###.#...###.####.#..#..#...#..#..####.#.###########..#.###.###.#.#
+##.##..##.####..###...##...#....###.###.#..##..#..#.###.#..####.#..##.#.#...#..#.#.##.##...#...#....
+..##...#.#.##....##...#.#.#......##.##.#.#.####.####....####.#.###.##.#.#..####..#..######..#..#.#..
+####.#.##.......##.###....##.#..####.#.#######..#...###..##.##..#...#...####........#.#..##...#....#
+#..#.#.....#..#.###..#.#...###..##...#.#..#.#.##..#...##.##.##.#.#.#..#.####.########....########..#
+#...#..##.##..#.#.#.##.##.##.#..#..#.##....#....###.#.###.#.#..#....#...##..#.....####...##.#..#...#
+.###...##...####....###.##.#..####...##.#.##.#..##..##....#....##.#...#..#..##..##..##.#...#...###..
+.#..##.#..##..####..#.#.##..###.#...#....##.###...#.###....#.#.#........#..#.#.#..##..#####..#..#.#.
+.#.##.....#..#...#.##.....#.##..#..#....#..#..#....#.##..##...#.##.##..##..#.#.#.##..####.##..#.#..#
+...###.#.....#...#.##.#.###.#...##..#.###..#..#..#.#..#...###.#.##.##.##.#.##.#####.#..#.#..#.#...##
+#.#.#.#.##.#.....##..#.###......##.#.##..#...#.########.##.###..#..#..##..##.#..##..###.#.###...#.#.
+..##...##...#...###.#..##..#..#..#.#.##..##......##..##.....##.....####..#.##......#..####...###..##
+##.......#..##....###...###......#.##.##....######..###.##...##.#...#...#.....#.###.#.#..#.##..#..#.
+#.#..#..#.#####.##.##.###..#...###.....#..##..####...#.#.###....#..#.#.###.####..#.#........##.#....
+..###.#...##.#.####.#.##.##.....##...#.##.#.###.#.#..##.#..##..#..##.##....#.#####.##..#######.....#
+###.###..##.#..##...#####..##.####....#.##......##......#.#....##.####.#.#.#.###...#..####..#.######
+#..###...#.#.......#..####.####...#....###.###...#.##..##..#..##.##.......####.##...#.#.#.##.#.#..#.
+..#...#..###.##..#.#.#.##..#..#.#.......###..###..#####.#.#.#.#.#..#.#.#.#..###....#.####..###...#..
+...######.###....#..####.####......#...#.###.#....#...####.##........##...##.#..##.###.#..#..##..###
+.#..###.####.###.#.#..#..#..#.##.#.#.###.##..####.#####..##....##.#.##...###.####.#.#######.#..#..#.
+.#..##.#..##..#...##...#..#..##.#.#....##.##...###.#.#...##..##..#.###.#.#.#.#...#....#.#..#.#.###.#
+.###..#.#..####.#########...####....####.#.##...##.##..#.##.#........#.....###.###.######.##.....###
+..##.##..##..#.####.#..#####.#....##.##.#####.....#.#......##...#####..####....###..#.#...#..####..#
+.#..##..##.##.##.##.#.###.###.#..#..#...###.#.##..##...##...###...##.###..#.#.#####.#.#.##....#.##..
+...#.#....##.#.....###.##...#..##....#...###....#..#.###...##.#...###.#....#...##..###.#.....##....#
+.#######..#...##.#.###.##.#.###...##......#.###.#...#.###.#.#.#..#..#####..#########...##..##...#..#
+.#..#.##...#.#..#.##..#.#.#.##.....####.#..#.###..##.#.#.#...#....#.#..##.######...#.#..##.##...#..#
+#.#######.#####..#####.##.##.#.#.##.###..#....####.#..##.##.######..###...#.#..#.####.##.##....####.
+...##..#...##..#..#.....#.##...#.....##.#####.###.########.######..#...###..#.##.#.#.##..#.#.##..##.
+#..#..#.#....###.#...##..####.#.##..#.####.###..##.#...#.###.#..#.##..#######.#...#..#.#..##.#....##
+..#.##.#.####..##.###.###..#.##.#.####..##....##.###.#..##.#.###.###.##.##.#####..#.#...########....
+.#.#.###..###...#...#..##.##......#..#...#.#.#.######.#.#...##..##........#....###..##...#..##.##...
+##..#....##.###...##.#.##.##.##..#....#.#.#..#..####.##..#...#...#..#..#####.###...#..###..#...#.#..
+##.#.#.##.###.....######.#.....#...#.##....###.#.##.#.#.##..##.######.#####....#.#####...##.#..###.#
+######.#...####..###..##..#..##...#.#....##.#...##...#.....#...##....#.##..###..###...###..#..######
+.....##.........#####.#.##..#..#.#.#.#.##...#....#.....###.########...#..####..#...#...##..#.##.##.#
+#..###...#.##.##.#.#..####.#.....##..###....##..#...#.#...##.##..###..####...#.####..##..#..##..#...
+#.####.#..##.#..#.....#..#.#..###...######.#.........####....###..#.#.#.##.#..#...#..####.....##..#.
+..##....#.###.......##.#...#.####..##....##.#..#....#######...####.##..#####.#.#.#.#.##..##..#.#.#..
+#.#.#.###..#..#.#..#.#.###....#...#####.###...........#.#....#####...#..####....#...###.#..#..####..
+.......#.####.##...#..#.##..###..#..#.#.#.#.###....#....#.#.#..#.#..##.#####.#.....#.##.#.###.###.##
+..###...#..#...####.#..##..##.#.#..#...#.#..#....###.#..####..######...####.#.##..#.#..###...##.####
+..#.###..#.#...##...#.#....#..#...#.#..##.######.######.#.##.....#..##.#..###..#..#.##.###...#..#.##
+####..##.####.....#...#.#.###..#...####.###.#.#.#.......##...#....#..#....#.#......###...#####.#.##.
+#..##..#..#.####...#####.#.###.##.#.##.....#.#..#.##........######.#.#.###....##.##..##..########.##
+#.#....###.##....#######.#...#.#.#.#..##.#.##...#.###...#.#.#..#.#..####.#.#..#..#.##.####....#..##.
+####.##....#.......###..#..##.#.#.##..#...#...##.###....##..###.#.#...#..#.....##.###.##...###....##
+..##.#..#....######..#.##.#.#...##..####.#####...##.#..###.##...#..####..###.##..##.##.#####.#..#.#.
+.#.##..#..##.#.###.###....#.#..#....#...###.##.#.#.####.....#....#...#.....#....#.#.###.#..#.##..###
+..###.#.#.##...##.##.##.#...#####.#..##.#....##..####...###..#....#.##...#........#####.#.###.#..#..
+....#..##..##....#.#....#.#..##...##.#...##.###.#.#..###..##.##.##..#.#.#..#.#.##.......#.##.###..#.
+.#..##.##.####.##....##.##.....###..##.#.##...#..###....###.###....#.#....#....#.##.#.##.#.##.....##
+#.#..#.##.###.#.######.....###.#..#...#.#.....##.###.#...#.#..###.#.....##.###.#.###.####..#####.#..
+#.#.##......#.##.#.#..##....#..###.#.###...##...###.#..#.##...#..#.##..##.#...######.##.....#####.##
+#.#..#####....###.###...#.......#....###.##...#..#.##..#...#####..#..#.##......###...#...###..#.#..#
+#.##..##.##.#..#.##.##..#.###.##.........###.#.#..#.#.....#.#...#.#.##.#.##.#...#...####.#.......##.
+.#...####.##..#..##....####..######...#.#..##.##.....#####.#...#..#.####.#######...#.#####..#.###...
+.#..######.#.##..##...##.....###.#..##..#...####..###...###.###..#..######.#....########..#####...#.
+#..##.......#####...###..#.#.##.#..###.#...##.#..#.##.###...###...##.#..##..########..#.#..##..#.###
+.#.#..#...#.#..#..##...#.#.##...###..#..#....###.#....#.##....###.###..##..#.#.####..####.#######.##
+...##..##.##.###.##.###...##.#.#.....##.####..#..##.#..#.####...##..#..#.##...##...###.##.#.......##
+.#.....#.##..#.#.....#.##.##..###..#....###...#.#....##########.##.###.#...#.####..####.#..#.#..###.
+.##.#.#.##..#..###.###.##.#########.#.#.#.#.##.###..##..#.##.####......#####...#..####.#.##..#####.#
+..#....###...##....#.###..##..#..####.##..####.#..####.###.#....####.....#.###..##...##..####...##.#
+.###.....###.##.##..###.###.....##..#.######.#.#..##..#.##.#..#.#.#....#...#.#.#...#...##....#..##.#
+..##....#..#####....#..####.#.#...##.#....##..##.###.###....###......#...#.#####.......#...#.....###
+###.#..#.#.##..#..#...#.#....###.##.#.###.#...#.##.#..#.#.......#.#.#.###.####.###....#..##..#####..
+.#..#######.#..###.#.##.#####.#####...##..#.####.#.#.##..###...#..##.##..#.#.###..#....#..#...###.#.
+..#####..#.##.....###..##.#...#.#.#..#######.#..#...#.##.##.#.#....####...###..##...#....####.#..#.#
+.####..#.#.##.###.#.##.....#..##.#.....###.....#..##...#....###.###..#......###.#.#.#.##.#.##..#...#
+##.#..##.#..##...#.#....##..######..#.....#..#...#####....##......####.##..#...##..#.##.#.#######..#
+##..####.#...##...#.#####.#.#..#....#.#..##.####.#..######.#..#..#.......#####..#..#..###.##...##.##
+#.####......#.###...#..####.#..##.##..#.#...##.###.#...#####..####.#..#.#.....#.##...###...#.#....##
+###.#.#.##.######......#.#.#.#.#........#..#..###.#.#.#..#.........#..#....#.#..#..#..###.##......##
+##.#########...#...###..#.###.....#.#.##.........###....#.####.#...###.#..##..#.###..#..##......#.##

+ 9 - 0
D18.2/D18.2.csproj

@@ -0,0 +1,9 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <OutputType>Exe</OutputType>
+    <TargetFramework>netcoreapp2.1</TargetFramework>
+    <RootNamespace>D18._2</RootNamespace>
+  </PropertyGroup>
+
+</Project>

+ 104 - 0
D18.2/Program.cs

@@ -0,0 +1,104 @@
+using System;
+using System.IO;
+using System.Linq;
+using System.Text;
+
+namespace D18._2
+{
+    class Program
+    {
+        static void Main(string[] args)
+        {
+            const int len = 100;
+
+            string input = ParseFile(args[0]);
+
+            for (int i = 0; i < 100; ++i)
+                input = Step(len, input);
+
+            int litOn = input.Count(c => c == '#');
+
+            Console.WriteLine($"The answer is : {litOn}");
+        }
+
+        private static string ParseFile(string arg)
+        {
+            var sb = new StringBuilder();
+            using (var file = File.OpenText(arg))
+            {
+                while (true)
+                {
+                    var line = file.ReadLine();
+                    if (line == null) break;
+
+                    sb.Append(line);
+                }
+            }
+
+            string input = sb.ToString();
+            return input;
+        }
+
+        private static string Step(int len, string input)
+        {
+            int edgeDetector = 0;
+            int totalSize = len * len;
+            int lastLineDetector = len * (len - 1);
+            int lastColumn = len - 1;
+
+            var stepb = new StringBuilder();
+            for (int i = 0; i < totalSize; ++i)
+            {
+                char state = input[i];
+                char nstate = state;
+
+                bool onFirstLine = i < len;
+                bool onLastLine = i >= lastLineDetector;
+
+                if ((onFirstLine && edgeDetector == 0) || (onFirstLine && edgeDetector == lastColumn) || (onLastLine && edgeDetector == 0) || (onLastLine && edgeDetector == lastColumn))
+                {
+                    edgeDetector = AppendState(edgeDetector, lastColumn, stepb, '#');
+                    continue;
+                }
+
+                int onNeighbors = DetectNeoghbors(len, input, edgeDetector, lastColumn, i, onFirstLine, onLastLine);
+
+                if (state == '#')
+                {
+                    if (onNeighbors != 2 && onNeighbors != 3) nstate = '.';
+                }
+                else
+                {
+                    if (onNeighbors == 3) nstate = '#';
+                }
+
+                edgeDetector = AppendState(edgeDetector, lastColumn, stepb, nstate);
+            }
+
+            return stepb.ToString();
+        }
+
+        private static int AppendState(int edgeDetector, int lastColumn, StringBuilder stepb, char nstate)
+        {
+            stepb.Append(nstate);
+
+            edgeDetector = edgeDetector == lastColumn ? 0 : edgeDetector + 1;
+            return edgeDetector;
+        }
+
+        private static int DetectNeoghbors(int len, string input, int edgeDetector, int lastColumn, int i, bool onFirstLine, bool onLastLine)
+        {
+            int onNeighbors = 0;
+
+            if (edgeDetector > 0) onNeighbors += input[i - 1] == '#' ? 1 : 0;
+            if (edgeDetector < lastColumn) onNeighbors += input[i + 1] == '#' ? 1 : 0;
+            if (onFirstLine == false) onNeighbors += input[i - len] == '#' ? 1 : 0;
+            if (onLastLine == false) onNeighbors += input[i + len] == '#' ? 1 : 0;
+            if (onFirstLine == false && edgeDetector > 0) onNeighbors += input[i - len - 1] == '#' ? 1 : 0;
+            if (onFirstLine == false && edgeDetector < lastColumn) onNeighbors += input[i - len + 1] == '#' ? 1 : 0;
+            if (onLastLine == false && edgeDetector > 0) onNeighbors += input[i + len - 1] == '#' ? 1 : 0;
+            if (onLastLine == false && edgeDetector < lastColumn) onNeighbors += input[i + len + 1] == '#' ? 1 : 0;
+            return onNeighbors;
+        }
+    }
+}

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

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