add Day base class like 2019's
This commit is contained in:
parent
9570b5e1a5
commit
072add7376
|
@ -0,0 +1,57 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
namespace aoc2020
|
||||
{
|
||||
public abstract class Day
|
||||
{
|
||||
public abstract int DayNumber { get; }
|
||||
public virtual IEnumerable<string> Input =>
|
||||
File.ReadLines($"input/day{DayNumber}.in");
|
||||
|
||||
public abstract string Part1();
|
||||
public abstract string Part2();
|
||||
|
||||
public virtual void AllParts(bool verbose = false)
|
||||
{
|
||||
Console.WriteLine($"Day {DayNumber}:");
|
||||
var s = new Stopwatch();
|
||||
|
||||
if (verbose)
|
||||
{
|
||||
s.Start();
|
||||
}
|
||||
|
||||
var part1 = Part1();
|
||||
|
||||
if (verbose)
|
||||
{
|
||||
s.Stop();
|
||||
Console.WriteLine($"Part 1 elapsed ticks: {s.ElapsedTicks}");
|
||||
}
|
||||
|
||||
Console.WriteLine(part1);
|
||||
|
||||
if (verbose)
|
||||
{
|
||||
s.Reset();
|
||||
s.Start();
|
||||
}
|
||||
|
||||
var part2 = Part2();
|
||||
|
||||
if (verbose)
|
||||
{
|
||||
s.Stop();
|
||||
Console.WriteLine($"Part 2 elapsed ticks: {s.ElapsedTicks}");
|
||||
}
|
||||
|
||||
Console.WriteLine(part2);
|
||||
Console.WriteLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
namespace aoc2020
|
||||
{
|
||||
internal class Day1 : Day
|
||||
{
|
||||
public override int DayNumber => 1;
|
||||
public override string Part1()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
public override string Part2()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
31
Program.cs
31
Program.cs
|
@ -1,12 +1,37 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace aoc2020
|
||||
{
|
||||
class Program
|
||||
internal class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("Hello World!");
|
||||
var days = Assembly.GetExecutingAssembly().GetTypes()
|
||||
.Where(t => t.BaseType == typeof(Day))
|
||||
.Select(t => (Day) Activator.CreateInstance(t))
|
||||
.OrderBy(d => d.DayNumber);
|
||||
|
||||
if (args.Length == 1 && int.TryParse(args[0], out var dayNum))
|
||||
{
|
||||
var day = days.FirstOrDefault(d => d.DayNumber == dayNum);
|
||||
if (day != null)
|
||||
{
|
||||
day.AllParts();
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"Day {dayNum} invalid or not yet implemented");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var d in days)
|
||||
{
|
||||
d.AllParts();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.30709.132
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "aoc2020", "aoc2020.csproj", "{3D60F1A0-0DD9-4FF9-B85B-D491B13ACAE7}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{3D60F1A0-0DD9-4FF9-B85B-D491B13ACAE7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{3D60F1A0-0DD9-4FF9-B85B-D491B13ACAE7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{3D60F1A0-0DD9-4FF9-B85B-D491B13ACAE7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{3D60F1A0-0DD9-4FF9-B85B-D491B13ACAE7}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {F1ECEA7D-4A0E-4B78-8D3C-29D4E1D09C0D}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
Loading…
Reference in New Issue