Create AdventOfCode.Common.

This commit is contained in:
2023-12-03 02:44:22 +01:00
parent b42aaa09c0
commit fd09931145
15 changed files with 54 additions and 161 deletions

View File

@@ -8,4 +8,14 @@
<RootNamespace>AdventOfCode2023</RootNamespace>
</PropertyGroup>
<ItemGroup>
<None Update="inputs\*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AdventOfCode.Common\AdventOfCode.Common.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,53 +0,0 @@
namespace AdventOfCode2023;
public interface IDay
{
string ResolvePart1(string[] inputs);
string ResolvePart2(string[] inputs);
}
public static class DayHelper
{
public static void RunDay(int currentDayNumber)
{
Console.WriteLine($"Day {currentDayNumber:00}");
Console.WriteLine("------");
Console.WriteLine();
IDay? currentDay = null;
Type? dayType = Type.GetType($"AdventOfCode2023.Day{currentDayNumber: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{currentDayNumber:00}.txt");
try
{
string resultPart1 = currentDay.ResolvePart1(linesDay);
Console.WriteLine("Day{1:00} Result Part1: {0}", resultPart1, currentDayNumber);
}
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, currentDayNumber);
}
catch (Exception ex)
{
Console.WriteLine("!!!!!!!");
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
}
}
}

View File

@@ -1 +1,3 @@
DayHelper.RunDay(2);
global using AdventOfCode.Common;
DayHelper.RunDay("AdventOfCode2023", 2);

View File

@@ -1 +0,0 @@
global using AdventOfCode2023;