bastien.monsarrat 6 tahun lalu
induk
melakukan
c8d53c831d
4 mengubah file dengan 96 tambahan dan 0 penghapusan
  1. 6 0
      Adv2018.sln
  2. 9 0
      D14.2/D14.2.csproj
  3. 73 0
      D14.2/Program.cs
  4. 8 0
      D14.2/Properties/launchSettings.json

+ 6 - 0
Adv2018.sln

@@ -61,6 +61,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D13.Bonus", "D13.Bonus\D13.
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D14.1", "D14.1\D14.1.csproj", "{FBA155A3-A591-4C0B-B89F-1C789340CC0D}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D14.2", "D14.2\D14.2.csproj", "{65499119-BBF5-4CF0-895F-F2DD94CD596F}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -183,6 +185,10 @@ Global
 		{FBA155A3-A591-4C0B-B89F-1C789340CC0D}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{FBA155A3-A591-4C0B-B89F-1C789340CC0D}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{FBA155A3-A591-4C0B-B89F-1C789340CC0D}.Release|Any CPU.Build.0 = Release|Any CPU
+		{65499119-BBF5-4CF0-895F-F2DD94CD596F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{65499119-BBF5-4CF0-895F-F2DD94CD596F}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{65499119-BBF5-4CF0-895F-F2DD94CD596F}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{65499119-BBF5-4CF0-895F-F2DD94CD596F}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

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

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

+ 73 - 0
D14.2/Program.cs

@@ -0,0 +1,73 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace D14._2
+{
+    class Program
+    {
+        static void Main(string[] args)
+        {
+            if (args.Length == 0) return;
+
+            string inputStr = args[0];
+            
+            int [] input = inputStr.Select(c => c - '0').ToArray();
+
+            int ccount = 0;
+            int count = 2;
+
+            int elf1 = 0;
+            int elf2 = 1;
+
+            var recipes = new List<int>() { 3, 7 };
+
+            do
+            {
+                int nrecipe = recipes[elf1] + recipes[elf2];
+
+                if (nrecipe < 10)
+                {
+                    recipes.Add(nrecipe);
+
+                    CheckInput(input, ref ccount, ref count, nrecipe);
+
+                }
+                else
+                {
+                    foreach (var nr in new[] { 1, nrecipe - 10 })
+                    {
+                        recipes.Add(nr);
+
+                        CheckInput(input, ref ccount, ref count, nr);
+
+                        if (ccount == input.Length) break;
+                    }
+                }
+
+                elf1 = (elf1 + 1 + recipes[elf1]) % recipes.Count;
+                elf2 = (elf2 + 1 + recipes[elf2]) % recipes.Count;
+
+            } while (ccount != input.Length);
+
+
+            Console.WriteLine(count.ToString());
+        }
+
+        private static void CheckInput(int[] input, ref int ccount, ref int count, int nrecipe)
+        {
+            if (input[ccount] == nrecipe) ccount++;
+            else if (input[0] == nrecipe)
+            {
+                count += ccount;
+                ccount = 1;
+            }
+            else
+            {
+                count += ccount + 1;
+                ccount = 0;
+            }
+        }
+    }
+}

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

@@ -0,0 +1,8 @@
+{
+  "profiles": {
+    "D14.2": {
+      "commandName": "Project",
+      "commandLineArgs": "633601"
+    }
+  }
+}