bastien.monsarrat 6 jaren geleden
bovenliggende
commit
bc7db3afdc
4 gewijzigde bestanden met toevoegingen van 77 en 0 verwijderingen
  1. 6 0
      Adv2016.sln
  2. 9 0
      D16.1/D16.csproj
  3. 54 0
      D16.1/Program.cs
  4. 8 0
      D16.1/Properties/launchSettings.json

+ 6 - 0
Adv2016.sln

@@ -55,6 +55,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "D14", "D14.1\D14.csproj", "
 EndProject
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "D15", "D15.1\D15.csproj", "{209B250E-7768-4444-9C94-D77208C3CFC4}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D16", "D16.1\D16.csproj", "{4B98BF9C-FDAF-474B-BF8E-FF5F91983E2E}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -165,6 +167,10 @@ Global
 		{209B250E-7768-4444-9C94-D77208C3CFC4}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{209B250E-7768-4444-9C94-D77208C3CFC4}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{209B250E-7768-4444-9C94-D77208C3CFC4}.Release|Any CPU.Build.0 = Release|Any CPU
+		{4B98BF9C-FDAF-474B-BF8E-FF5F91983E2E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{4B98BF9C-FDAF-474B-BF8E-FF5F91983E2E}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{4B98BF9C-FDAF-474B-BF8E-FF5F91983E2E}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{4B98BF9C-FDAF-474B-BF8E-FF5F91983E2E}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

+ 9 - 0
D16.1/D16.csproj

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

+ 54 - 0
D16.1/Program.cs

@@ -0,0 +1,54 @@
+using System;
+using System.Collections;
+using System.Text;
+
+namespace D16._1
+{
+    class Program
+    {
+        static void Main(string[] args)
+        {
+            Console.WriteLine($"Part 1 : {FillHardDrive(args[0], 272)}");
+            Console.WriteLine($"Part 2 : {FillHardDrive(args[0], 35651584)}");
+        }
+
+        private static string FillHardDrive(string input, int diskSize)
+        {
+            bool[] bs = new bool[input.Length];
+            for (int i = 0; i < input.Length; i++)
+                bs[i] = input[i] == '1' ? true : false;
+
+            var ba = new BitArray(bs);
+            while (ba.Length < diskSize)
+            {
+                var bab = new BitArray(ba.Length * 2 + 1);
+                var l = ba.Count;
+
+                for (int i = 0; i < l; ++i)
+                {
+                    bab.Set(i, ba.Get(i));
+                    bab.Set(l + l - i, !ba.Get(i));
+                }
+
+                ba = bab;
+            }
+
+            int le = diskSize;
+            while (ba.Length > 17)
+            {
+                le /= 2;
+                BitArray cs = new BitArray(le);
+                for (int i = 0; i < le; ++i)
+                {
+                    var p = ((ba.Get(i * 2) ? 1 : 0) << 1) + (ba.Get(i * 2 + 1) ? 1 : 0);
+                    cs.Set(i, p == 0b11 || p == 0b00);
+                }
+                ba = cs;
+            }
+
+            var sb = new StringBuilder();
+            foreach (bool b in ba) sb.Append(b ? "1" : "0");
+            return sb.ToString();
+        }
+    }
+}

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

@@ -0,0 +1,8 @@
+{
+  "profiles": {
+    "D16.1": {
+      "commandName": "Project",
+      "commandLineArgs": "10111011111001111"
+    }
+  }
+}