Create AdventOfCode.Common.
This commit is contained in:
9
AdventOfCode.Common/AdventOfCode.Common.csproj
Normal file
9
AdventOfCode.Common/AdventOfCode.Common.csproj
Normal file
@@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
47
AdventOfCode.Common/DayHelper.cs
Normal file
47
AdventOfCode.Common/DayHelper.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
namespace AdventOfCode.Common;
|
||||
|
||||
public static class DayHelper
|
||||
{
|
||||
public static void RunDay(string eventName, int dayNumber)
|
||||
{
|
||||
Console.WriteLine($"Day {dayNumber:00}");
|
||||
Console.WriteLine("------");
|
||||
Console.WriteLine();
|
||||
|
||||
IDay? currentDay = null;
|
||||
Type? dayType = Type.GetType($"{eventName}.Day{dayNumber:00}");
|
||||
if (dayType != null)
|
||||
{
|
||||
currentDay = Activator.CreateInstance(dayType) as IDay;
|
||||
}
|
||||
if (currentDay == null)
|
||||
{
|
||||
Console.WriteLine("!!!!!!!");
|
||||
Console.WriteLine("Day implementation not found.");
|
||||
return;
|
||||
}
|
||||
|
||||
string[] linesDay = File.ReadAllLines($"inputs/Day{dayNumber:00}.txt");
|
||||
try
|
||||
{
|
||||
string resultPart1 = currentDay.ResolvePart1(linesDay);
|
||||
Console.WriteLine("Day{1:00} Result Part1: {0}", resultPart1, dayNumber);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
Console.WriteLine(ex.StackTrace);
|
||||
}
|
||||
try
|
||||
{
|
||||
string resultPart2 = currentDay.ResolvePart2(linesDay);
|
||||
Console.WriteLine("Day{1:00} Result Part2: {0}", resultPart2, dayNumber);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("!!!!!!!");
|
||||
Console.WriteLine(ex.Message);
|
||||
Console.WriteLine(ex.StackTrace);
|
||||
}
|
||||
}
|
||||
}
|
||||
7
AdventOfCode.Common/IDay.cs
Normal file
7
AdventOfCode.Common/IDay.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace AdventOfCode.Common;
|
||||
|
||||
public interface IDay
|
||||
{
|
||||
string ResolvePart1(string[] inputs);
|
||||
string ResolvePart2(string[] inputs);
|
||||
}
|
||||
Reference in New Issue
Block a user