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>
|
||||
@@ -1,21 +1,15 @@
|
||||
namespace AdventOfCode2023;
|
||||
|
||||
public interface IDay
|
||||
{
|
||||
string ResolvePart1(string[] inputs);
|
||||
string ResolvePart2(string[] inputs);
|
||||
}
|
||||
namespace AdventOfCode.Common;
|
||||
|
||||
public static class DayHelper
|
||||
{
|
||||
public static void RunDay(int currentDayNumber)
|
||||
public static void RunDay(string eventName, int dayNumber)
|
||||
{
|
||||
Console.WriteLine($"Day {currentDayNumber:00}");
|
||||
Console.WriteLine($"Day {dayNumber:00}");
|
||||
Console.WriteLine("------");
|
||||
Console.WriteLine();
|
||||
|
||||
IDay? currentDay = null;
|
||||
Type? dayType = Type.GetType($"AdventOfCode2023.Day{currentDayNumber:00}");
|
||||
Type? dayType = Type.GetType($"{eventName}.Day{dayNumber:00}");
|
||||
if (dayType != null)
|
||||
{
|
||||
currentDay = Activator.CreateInstance(dayType) as IDay;
|
||||
@@ -27,11 +21,11 @@ public static class DayHelper
|
||||
return;
|
||||
}
|
||||
|
||||
string[] linesDay = File.ReadAllLines($"inputs/Day{currentDayNumber:00}.txt");
|
||||
string[] linesDay = File.ReadAllLines($"inputs/Day{dayNumber:00}.txt");
|
||||
try
|
||||
{
|
||||
string resultPart1 = currentDay.ResolvePart1(linesDay);
|
||||
Console.WriteLine("Day{1:00} Result Part1: {0}", resultPart1, currentDayNumber);
|
||||
Console.WriteLine("Day{1:00} Result Part1: {0}", resultPart1, dayNumber);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -41,7 +35,7 @@ public static class DayHelper
|
||||
try
|
||||
{
|
||||
string resultPart2 = currentDay.ResolvePart2(linesDay);
|
||||
Console.WriteLine("Day{1:00} Result Part2: {0}", resultPart2, currentDayNumber);
|
||||
Console.WriteLine("Day{1:00} Result Part2: {0}", resultPart2, dayNumber);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace AdventOfCode2017;
|
||||
namespace AdventOfCode.Common;
|
||||
|
||||
public interface IDay
|
||||
{
|
||||
@@ -19,6 +19,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdventOfCode2023", "AdventO
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdventOfCode2023.Tests", "AdventOfCode2023.Tests\AdventOfCode2023.Tests.csproj", "{00869F26-F53E-451D-BEA2-4E3FFE2216FB}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdventOfCode.Common", "AdventOfCode.Common\AdventOfCode.Common.csproj", "{D6C2B27F-22C3-49E2-9591-225B7132452D}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -57,6 +59,10 @@ Global
|
||||
{00869F26-F53E-451D-BEA2-4E3FFE2216FB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{00869F26-F53E-451D-BEA2-4E3FFE2216FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{00869F26-F53E-451D-BEA2-4E3FFE2216FB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{D6C2B27F-22C3-49E2-9591-225B7132452D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{D6C2B27F-22C3-49E2-9591-225B7132452D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D6C2B27F-22C3-49E2-9591-225B7132452D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D6C2B27F-22C3-49E2-9591-225B7132452D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -11,4 +11,8 @@
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AdventOfCode.Common\AdventOfCode.Common.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,28 +1,3 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
global using AdventOfCode.Common;
|
||||
|
||||
namespace AdventOfCode2017;
|
||||
|
||||
public class Program
|
||||
{
|
||||
private static void Main()
|
||||
{
|
||||
int currentDayNumber = 3;
|
||||
IDay currentDay = null;
|
||||
|
||||
switch (currentDayNumber)
|
||||
{
|
||||
case 1: currentDay = new Day01(); break;
|
||||
case 2: currentDay = new Day02(); break;
|
||||
case 3: currentDay = new Day03(); break;
|
||||
}
|
||||
|
||||
string[] linesDay = File.ReadAllLines($"inputs/Day{currentDayNumber:00}.txt");
|
||||
string resultPart1 = currentDay.ResolvePart1(linesDay);
|
||||
Console.WriteLine("Day{1:00} Result Part1: {0}", resultPart1, currentDayNumber);
|
||||
string resultPart2 = currentDay.ResolvePart2(linesDay);
|
||||
Console.WriteLine("Day{1:00} Result Part2: {0}", resultPart2, currentDayNumber);
|
||||
|
||||
Console.Read();
|
||||
}
|
||||
}
|
||||
DayHelper.RunDay("AdventOfCode2017", 2);
|
||||
@@ -11,4 +11,8 @@
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AdventOfCode.Common\AdventOfCode.Common.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
namespace AdventOfCode2018;
|
||||
|
||||
public interface IDay
|
||||
{
|
||||
string ResolvePart1(string[] inputs);
|
||||
string ResolvePart2(string[] inputs);
|
||||
}
|
||||
@@ -1,41 +1,3 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
global using AdventOfCode.Common;
|
||||
|
||||
namespace AdventOfCode2018;
|
||||
|
||||
internal class Program
|
||||
{
|
||||
private static void Main()
|
||||
{
|
||||
int currentDayNumber = 15;
|
||||
IDay currentDay = null;
|
||||
|
||||
switch (currentDayNumber)
|
||||
{
|
||||
case 1: currentDay = new Day01(); break;
|
||||
case 2: currentDay = new Day02(); break;
|
||||
case 3: currentDay = new Day03(); break;
|
||||
case 4: currentDay = new Day04(); break;
|
||||
case 5: currentDay = new Day05(); break;
|
||||
case 6: currentDay = new Day06(); break;
|
||||
case 7: currentDay = new Day07(); break;
|
||||
case 8: currentDay = new Day08(); break;
|
||||
case 9: currentDay = new Day09(); break;
|
||||
case 10: currentDay = new Day10(); break;
|
||||
case 11: currentDay = new Day11(); break;
|
||||
case 12: currentDay = new Day12(); break;
|
||||
case 13: currentDay = new Day13(); break;
|
||||
case 14: currentDay = new Day14(); break;
|
||||
case 15: currentDay = new Day15(); break;
|
||||
case 23: currentDay = new Day23(); break;
|
||||
}
|
||||
|
||||
string[] linesDay = File.ReadAllLines($"inputs/Day{currentDayNumber:00}.txt");
|
||||
string resultPart1 = currentDay.ResolvePart1(linesDay);
|
||||
Console.WriteLine("Day{1:00} Result Part1: {0}", resultPart1, currentDayNumber);
|
||||
string resultPart2 = currentDay.ResolvePart2(linesDay);
|
||||
Console.WriteLine("Day{1:00} Result Part2: {0}", resultPart2, currentDayNumber);
|
||||
|
||||
Console.Read();
|
||||
}
|
||||
}
|
||||
DayHelper.RunDay("AdventOfCode2018", 2);
|
||||
@@ -11,4 +11,8 @@
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AdventOfCode.Common\AdventOfCode.Common.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
namespace AdventOfCode2020;
|
||||
|
||||
public interface IDay
|
||||
{
|
||||
string ResolvePart1(string[] inputs);
|
||||
string ResolvePart2(string[] inputs);
|
||||
}
|
||||
@@ -1,65 +1,3 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
global using AdventOfCode.Common;
|
||||
|
||||
namespace AdventOfCode2020;
|
||||
|
||||
class Program
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
int currentDayNumber = 0;
|
||||
|
||||
DateTime date = DateTime.UtcNow.AddHours(-5);
|
||||
if (date.Month == 12 && currentDayNumber == 0)
|
||||
{
|
||||
currentDayNumber = date.Day;
|
||||
}
|
||||
|
||||
RunDay(currentDayNumber);
|
||||
|
||||
Console.Read();
|
||||
}
|
||||
|
||||
public static void RunDay(int currentDayNumber)
|
||||
{
|
||||
Console.WriteLine($"Day {currentDayNumber:00}");
|
||||
Console.WriteLine("------");
|
||||
Console.WriteLine();
|
||||
|
||||
IDay currentDay = null;
|
||||
Type dayType = Type.GetType($"AdventOfCode2020.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
DayHelper.RunDay("AdventOfCode2020", 2);
|
||||
@@ -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>
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
DayHelper.RunDay(2);
|
||||
global using AdventOfCode.Common;
|
||||
|
||||
DayHelper.RunDay("AdventOfCode2023", 2);
|
||||
@@ -1 +0,0 @@
|
||||
global using AdventOfCode2023;
|
||||
Reference in New Issue
Block a user