bastien.monsarrat 6 years ago
parent
commit
9c01647f5e
5 changed files with 302 additions and 0 deletions
  1. 6 0
      Adv2016.sln
  2. 9 0
      D08.1/D08.csproj
  3. 86 0
      D08.1/Program.cs
  4. 8 0
      D08.1/Properties/launchSettings.json
  5. 193 0
      D08.1/input.txt

+ 6 - 0
Adv2016.sln

@@ -31,6 +31,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D07.1", "D07.1\D07.1.csproj
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D07.2", "D07.2\D07.2.csproj", "{71BA5023-80E3-4B4D-A743-4CD66256C5A0}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D08", "D08.1\D08.csproj", "{F9878C0B-C390-457F-AB83-4E59494BE9FD}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -93,6 +95,10 @@ Global
 		{71BA5023-80E3-4B4D-A743-4CD66256C5A0}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{71BA5023-80E3-4B4D-A743-4CD66256C5A0}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{71BA5023-80E3-4B4D-A743-4CD66256C5A0}.Release|Any CPU.Build.0 = Release|Any CPU
+		{F9878C0B-C390-457F-AB83-4E59494BE9FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{F9878C0B-C390-457F-AB83-4E59494BE9FD}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{F9878C0B-C390-457F-AB83-4E59494BE9FD}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{F9878C0B-C390-457F-AB83-4E59494BE9FD}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

+ 9 - 0
D08.1/D08.csproj

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

+ 86 - 0
D08.1/Program.cs

@@ -0,0 +1,86 @@
+using System;
+using System.IO;
+using System.Linq;
+
+namespace D08._1
+{
+    class Program
+    {
+        static readonly int W = 50, H = 6;
+        static bool[,] LCD = new bool[H, W];
+
+        static void DrawRect(int w, int h)
+        {
+            for (var i = 0; i < h; i++)
+                for (var j = 0; j < w; j++)
+                    LCD[i, j] = true;
+        }
+
+        static void RotateRow(int r, int d)
+        {
+            var row = new bool[W];
+            for (var i = d; i < W + d; i++) row[i % W] = LCD[r, i - d];
+            for (var i = 0; i < W; i++) LCD[r, i] = row[i];
+        }
+
+        static void RotateColumn(int c, int d)
+        {
+            var col = new bool[H];
+            for (var i = d; i < H + d; i++) col[i % H] = LCD[i - d, c];
+            for (var i = 0; i < H; i++) LCD[i, c] = col[i];
+        }
+
+        static void Main(string[] args)
+        {
+            if (args.Length < 1) throw new ArgumentException();
+            if (File.Exists(args[0]) == false) throw new FileNotFoundException();
+
+            using (var file = File.OpenText(args[0]))
+            {
+                while (true)
+                {
+                    var line = file.ReadLine();
+                    if (line == null) break;
+
+                    if (line.StartsWith("rect "))
+                    {
+                        var lr = line.Split(" ")[1].Split("x");
+                        DrawRect(int.Parse(lr[0]), int.Parse(lr[1]));
+                    }
+
+                    if (line.StartsWith("rotate "))
+                    {
+                        var words = line.Split(" ");
+                        var type = words[1];
+                        var rc = words[2].Split("=")[1];
+                        var d = words[4];
+
+                        if (type == "row") RotateRow(int.Parse(rc), int.Parse(d));
+                        if (type == "column") RotateColumn(int.Parse(rc), int.Parse(d));
+                    }
+                }
+            }
+
+            int answer = Print();
+
+            Console.WriteLine($"The answer is : {answer}");
+        }
+
+        private static int Print()
+        {
+            int answer = 0;
+            for (var i = 0; i < H; i++)
+            {
+                for (var j = 0; j < W; j++)
+                {
+                    if (LCD[i, j]) answer++;
+                    Console.Write(LCD[i, j] ? '#' : '.');
+                }
+                Console.WriteLine();
+            }
+            Console.WriteLine();
+
+            return answer;
+        }
+    }
+}

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

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

+ 193 - 0
D08.1/input.txt

@@ -0,0 +1,193 @@
+rect 1x1
+rotate row y=0 by 5
+rect 1x1
+rotate row y=0 by 5
+rect 1x1
+rotate row y=0 by 5
+rect 1x1
+rotate row y=0 by 5
+rect 1x1
+rotate row y=0 by 2
+rect 1x1
+rotate row y=0 by 2
+rect 1x1
+rotate row y=0 by 3
+rect 1x1
+rotate row y=0 by 3
+rect 2x1
+rotate row y=0 by 2
+rect 1x1
+rotate row y=0 by 3
+rect 2x1
+rotate row y=0 by 2
+rect 1x1
+rotate row y=0 by 3
+rect 2x1
+rotate row y=0 by 5
+rect 4x1
+rotate row y=0 by 5
+rotate column x=0 by 1
+rect 4x1
+rotate row y=0 by 10
+rotate column x=5 by 2
+rotate column x=0 by 1
+rect 9x1
+rotate row y=2 by 5
+rotate row y=0 by 5
+rotate column x=0 by 1
+rect 4x1
+rotate row y=2 by 5
+rotate row y=0 by 5
+rotate column x=0 by 1
+rect 4x1
+rotate column x=40 by 1
+rotate column x=27 by 1
+rotate column x=22 by 1
+rotate column x=17 by 1
+rotate column x=12 by 1
+rotate column x=7 by 1
+rotate column x=2 by 1
+rotate row y=2 by 5
+rotate row y=1 by 3
+rotate row y=0 by 5
+rect 1x3
+rotate row y=2 by 10
+rotate row y=1 by 7
+rotate row y=0 by 2
+rotate column x=3 by 2
+rotate column x=2 by 1
+rotate column x=0 by 1
+rect 4x1
+rotate row y=2 by 5
+rotate row y=1 by 3
+rotate row y=0 by 3
+rect 1x3
+rotate column x=45 by 1
+rotate row y=2 by 7
+rotate row y=1 by 10
+rotate row y=0 by 2
+rotate column x=3 by 1
+rotate column x=2 by 2
+rotate column x=0 by 1
+rect 4x1
+rotate row y=2 by 13
+rotate row y=0 by 5
+rotate column x=3 by 1
+rotate column x=0 by 1
+rect 4x1
+rotate row y=3 by 10
+rotate row y=2 by 10
+rotate row y=0 by 5
+rotate column x=3 by 1
+rotate column x=2 by 1
+rotate column x=0 by 1
+rect 4x1
+rotate row y=3 by 8
+rotate row y=0 by 5
+rotate column x=3 by 1
+rotate column x=2 by 1
+rotate column x=0 by 1
+rect 4x1
+rotate row y=3 by 17
+rotate row y=2 by 20
+rotate row y=0 by 15
+rotate column x=13 by 1
+rotate column x=12 by 3
+rotate column x=10 by 1
+rotate column x=8 by 1
+rotate column x=7 by 2
+rotate column x=6 by 1
+rotate column x=5 by 1
+rotate column x=3 by 1
+rotate column x=2 by 2
+rotate column x=0 by 1
+rect 14x1
+rotate row y=1 by 47
+rotate column x=9 by 1
+rotate column x=4 by 1
+rotate row y=3 by 3
+rotate row y=2 by 10
+rotate row y=1 by 8
+rotate row y=0 by 5
+rotate column x=2 by 2
+rotate column x=0 by 2
+rect 3x2
+rotate row y=3 by 12
+rotate row y=2 by 10
+rotate row y=0 by 10
+rotate column x=8 by 1
+rotate column x=7 by 3
+rotate column x=5 by 1
+rotate column x=3 by 1
+rotate column x=2 by 1
+rotate column x=1 by 1
+rotate column x=0 by 1
+rect 9x1
+rotate row y=0 by 20
+rotate column x=46 by 1
+rotate row y=4 by 17
+rotate row y=3 by 10
+rotate row y=2 by 10
+rotate row y=1 by 5
+rotate column x=8 by 1
+rotate column x=7 by 1
+rotate column x=6 by 1
+rotate column x=5 by 1
+rotate column x=3 by 1
+rotate column x=2 by 2
+rotate column x=1 by 1
+rotate column x=0 by 1
+rect 9x1
+rotate column x=32 by 4
+rotate row y=4 by 33
+rotate row y=3 by 5
+rotate row y=2 by 15
+rotate row y=0 by 15
+rotate column x=13 by 1
+rotate column x=12 by 3
+rotate column x=10 by 1
+rotate column x=8 by 1
+rotate column x=7 by 2
+rotate column x=6 by 1
+rotate column x=5 by 1
+rotate column x=3 by 1
+rotate column x=2 by 1
+rotate column x=1 by 1
+rotate column x=0 by 1
+rect 14x1
+rotate column x=39 by 3
+rotate column x=35 by 4
+rotate column x=20 by 4
+rotate column x=19 by 3
+rotate column x=10 by 4
+rotate column x=9 by 3
+rotate column x=8 by 3
+rotate column x=5 by 4
+rotate column x=4 by 3
+rotate row y=5 by 5
+rotate row y=4 by 5
+rotate row y=3 by 33
+rotate row y=1 by 30
+rotate column x=48 by 1
+rotate column x=47 by 5
+rotate column x=46 by 5
+rotate column x=45 by 1
+rotate column x=43 by 1
+rotate column x=38 by 3
+rotate column x=37 by 3
+rotate column x=36 by 5
+rotate column x=35 by 1
+rotate column x=33 by 1
+rotate column x=32 by 5
+rotate column x=31 by 5
+rotate column x=30 by 1
+rotate column x=23 by 4
+rotate column x=22 by 3
+rotate column x=21 by 3
+rotate column x=20 by 1
+rotate column x=12 by 2
+rotate column x=11 by 2
+rotate column x=3 by 5
+rotate column x=2 by 5
+rotate column x=1 by 3
+rotate column x=0 by 4