|
|
@@ -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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|