bastien.monsarrat 6 жил өмнө
parent
commit
b84814c0dc

+ 7 - 1
Adv2015.sln

@@ -83,7 +83,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "D22.1", "D22.1\D22.1.csproj
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D22.2", "D22.2\D22.2.csproj", "{63AEC02B-5420-4D45-B48E-BBBEA9F6FA5F}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D23.1", "D23.1\D23.1.csproj", "{777A3D19-DEFC-4E94-9E7B-7D8F1E87027B}"
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D23", "D23.1\D23.csproj", "{777A3D19-DEFC-4E94-9E7B-7D8F1E87027B}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D24", "D24.1\D24.csproj", "{7E1EFA57-3A85-44B1-9FE1-9D5D83AD1160}"
 EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -255,6 +257,10 @@ Global
 		{777A3D19-DEFC-4E94-9E7B-7D8F1E87027B}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{777A3D19-DEFC-4E94-9E7B-7D8F1E87027B}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{777A3D19-DEFC-4E94-9E7B-7D8F1E87027B}.Release|Any CPU.Build.0 = Release|Any CPU
+		{7E1EFA57-3A85-44B1-9FE1-9D5D83AD1160}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{7E1EFA57-3A85-44B1-9FE1-9D5D83AD1160}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{7E1EFA57-3A85-44B1-9FE1-9D5D83AD1160}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{7E1EFA57-3A85-44B1-9FE1-9D5D83AD1160}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

+ 0 - 0
D23.1/D23.1.csproj → D23.1/D23.csproj


+ 9 - 0
D24.1/D24.csproj

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

+ 43 - 0
D24.1/Program.cs

@@ -0,0 +1,43 @@
+using System;
+using System.IO;
+using System.Linq;
+
+namespace D24._1
+{
+    class Program
+    {
+        static void Main(string[] args)
+        {
+            if (args.Length < 1) throw new ArgumentException();
+            if (File.Exists(args[0]) == false) throw new FileNotFoundException();
+
+            int[] presentsWeight = File.ReadAllLines(args[0]).Select(i => int.Parse(i)).ToArray();
+
+            var sum = presentsWeight.Sum();
+
+            var p1 = Test(presentsWeight, sum / 3);
+            var p2 = Test(presentsWeight, sum / 4);
+
+            Console.WriteLine($"The part1 answer is : {p1}");
+            Console.WriteLine($"The part2 answer is : {p2}");
+        }
+
+        static double? Test(int[] presentsWeight, int weight, double quantumE = 1, int totalWeight = 0, int i = 0 )
+        {
+            if (totalWeight == weight)
+                return quantumE;
+
+            if (i >= presentsWeight.Length || totalWeight > weight)
+                return null;
+
+            var take = Test(presentsWeight, weight, quantumE * presentsWeight[i], totalWeight + presentsWeight[i], i + 1);
+
+            var ignore = Test(presentsWeight, weight, quantumE, totalWeight, i + 1);
+
+            if (take == null) return ignore;
+            if (ignore == null) return take;
+
+            return Math.Min(take.GetValueOrDefault(0), ignore.GetValueOrDefault(0));
+        }
+    }
+}

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

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

+ 29 - 0
D24.1/input.txt

@@ -0,0 +1,29 @@
+1
+2
+3
+7
+11
+13
+17
+19
+23
+31
+37
+41
+43
+47
+53
+59
+61
+67
+71
+73
+79
+83
+89
+97
+101
+103
+107
+109
+113