aoc2021/aoc2021/Day.cs

46 lines
1.2 KiB
C#
Raw Normal View History

2021-11-11 05:19:35 +00:00
namespace aoc2021;
public abstract class Day
{
protected Day(int dayNumber, string puzzleName)
{
DayNumber = dayNumber;
PuzzleName = puzzleName;
}
2021-12-01 15:10:43 +00:00
public static bool UseTestInput { get; set; }
2021-11-11 05:19:35 +00:00
public int DayNumber { get; }
public string PuzzleName { get; }
protected IEnumerable<string> Input =>
File.ReadLines(FileName);
2021-12-01 15:10:43 +00:00
public string FileName =>
Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
$"input/{(UseTestInput ? "test" : "day")}{DayNumber,2:00}.in");
2021-11-11 05:19:35 +00:00
public abstract string Part1();
public abstract string Part2();
public void AllParts(bool verbose = true)
{
Console.WriteLine($"Day {DayNumber,2}: {PuzzleName}");
var s = Stopwatch.StartNew();
var part1 = Part1();
s.Stop();
2021-12-10 18:12:26 +00:00
Console.Write($"Part 1: {part1,-25} ");
2021-11-11 05:19:35 +00:00
Console.WriteLine(verbose ? $"{s.ScaleMilliseconds()}ms elapsed" : "");
s.Reset();
s.Start();
var part2 = Part2();
s.Stop();
2021-12-10 18:12:26 +00:00
Console.Write($"Part 2: {part2,-25} ");
2021-11-11 05:19:35 +00:00
Console.WriteLine(verbose ? $"{s.ScaleMilliseconds()}ms elapsed" : "");
Console.WriteLine();
}
}