Exemple #1
0
        private static void RunDay(IDay day, string input)
        {
            Console.WriteLine($"{day.GetType().Name}, {nameof(IDay.Part1)}");
            day.Part1(input);
            Console.WriteLine();

            Console.WriteLine($"{day.GetType().Name}, {nameof(IDay.Part2)}");
            day.Part2(input);
            Console.WriteLine();
        }
        public static void Run(IDay day)
        {
            var name = day.GetType().ToString();

            Console.WriteLine($"===================={name}====================");
            Console.WriteLine($"Part1: {day.Part1()}");
            Console.WriteLine($"Part2: {day.Part2()}");
            Console.WriteLine("==================================================");
        }
Exemple #3
0
        private static void RunDay(IDay day)
        {
            var sw = new Stopwatch();

            Console.WriteLine($"{day.GetType().Name}, {nameof(IDay.Part1)}");
            sw.Start();
            var r1 = day.Part1();

            sw.Stop();
            Console.WriteLine("Result: {0}\n", r1);
            Console.WriteLine("Time: {0}\n", sw.Elapsed);

            Console.WriteLine($"{day.GetType().Name}, {nameof(IDay.Part2)}");
            sw.Restart();
            var r2 = day.Part2();

            sw.Stop();
            Console.WriteLine("Result: {0}\n", r2);
            Console.WriteLine("Time: {0}\n", sw.Elapsed);
        }
Exemple #4
0
        void Start(IDay day, int index)
        {
            day.Create(index);

            var m = day.GetType()
                    .GetMethod("Start", BindingFlags.NonPublic | BindingFlags.Instance);

            if (m != null)
            {
                m.Invoke(day, new object[] { });
            }
        }
Exemple #5
0
        private float DoBenchmark(IDay day, int iterations)
        {
            GC.Collect();
            Stopwatch sw = Stopwatch.StartNew();

            // Run once for slow days...
            if (SlowDays.Contains(day.GetType().Name))
            {
                day.GetAnswerA();
                day.GetAnswerB();
                sw.Stop();
                return(sw.ElapsedMilliseconds);
            }
            else
            {
                for (int i = 0; i < iterations; i++)
                {
                    day.GetAnswerA();
                    day.GetAnswerB();
                }
            }
            sw.Stop();
            return(sw.ElapsedMilliseconds / (iterations * 1.0f));
        }
 static void ShowDayResult(IDay day)
 {
     Console.WriteLine($"{ day.GetType().Name }");
     Console.WriteLine($"Part 1: { day.FirstStarString }");
     Console.WriteLine($"Part 2: { day.SecondStarString }");
 }
Exemple #7
0
 public static string[] ReadInput(this IDay me)
 {
     return(new Input().ReadFile(me.GetType().Name + ".txt"));
 }
Exemple #8
0
 private static string PrintResult(IDay day, string method, object result) =>
 $"{day.GetType().Name}.{method}: {result} ({result != null && result.Equals(ExpectedResult.GetExpectedResult(day, method))})";