Esempio n. 1
0
 public DayThreadHarness(string input, BaseDay day, int part, Action <string, long> dayCompleteCallback)
 {
     _input = input;
     _day   = day;
     _part  = part;
     _dayCompleteCallback = dayCompleteCallback;
 }
Esempio n. 2
0
        private static BaseDay[] CollectDays()
        {
            var allDayTypes = Assembly.GetExecutingAssembly().GetTypes().Where(t =>
            {
                return(typeof(BaseDay).IsAssignableFrom(t) &&
                       !t.IsAbstract);
            }).ToArray();

            var allDays = new BaseDay[allDayTypes.Length];

            for (int i = 0; i < allDays.Length; i++)
            {
                allDays[i] = Activator.CreateInstance(allDayTypes[i]) as BaseDay;
            }

            allDays.OrderBy(d => (d.Year() * 100) + d.Day());
            return(allDays);
        }
Esempio n. 3
0
        private (string result, long elapsed) RunDay(string input, BaseDay runner, int part)
        {
            string result;
            var    start = Stopwatch.StartNew();

            if (part == 1)
            {
                result = runner.PartOne(input);
            }
            else
            {
                result = runner.PartTwo(input);
            }

            var end = start.ElapsedMilliseconds;

            return(result, end);
        }
        private (string result, long elapsed, long elapsedTicks) RunDay(string input, BaseDay runner, int part)
        {
            string result;
            var    start = Stopwatch.StartNew();

            try
            {
                if (part == 1)
                {
                    result = runner.PartOne(input);
                }
                else
                {
                    result = runner.PartTwo(input);
                }
            } catch (Exception ex)
            {
                result = ex.ToString();
            }

            var end = start.ElapsedTicks;

            return(result, start.ElapsedMilliseconds, start.ElapsedTicks);
        }