about summary refs log tree commit diff
path: root/Day.cs
blob: eb3ef49af3223c8842324d4778106cea23b65a2a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using aoc2019.lib;

namespace aoc2019
{
    public abstract class Day
    {
        protected Day(int dayNumber, string puzzleName)
        {
            DayNumber = dayNumber;
            PuzzleName = puzzleName;
        }

        public int DayNumber { get; }
        public string PuzzleName { get; }

        protected virtual IEnumerable<string> Input =>
            File.ReadLines(FileName);

        protected string FileName =>
            Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"input/day{DayNumber,2:00}.in");

        public void AllParts(bool verbose = true)
        {
            Console.WriteLine($"Day {DayNumber,2}: {PuzzleName}");
            var s = Stopwatch.StartNew();
            var part1 = Part1();
            s.Stop();
            Console.Write($"Part1: {part1,-15} ");
            Console.WriteLine(verbose ? $"{s.ScaleMilliseconds()}ms elapsed" : "");

            s.Reset();

            s.Start();
            var part2 = Part2();
            s.Stop();
            Console.Write($"Part2: {part2,-15} ");
            Console.WriteLine(verbose ? $"{s.ScaleMilliseconds()}ms elapsed" : "");

            Console.WriteLine();
        }

        protected abstract string Part1();
        protected abstract string Part2();
    }
}