moved code, started new core lib for main used items like string manipulation and data reading/parsing

This commit is contained in:
Rob 2023-12-02 22:50:40 +01:00
parent bc39465ce5
commit 27247c645e
47 changed files with 152 additions and 118 deletions

View File

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net8.0</TargetFramework>
<RootNamespace>AdventOFCodeRunner</RootNamespace> <RootNamespace>AdventOFCodeRunner</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>

View File

@ -1,7 +1,7 @@
using System.Text; using System.Text;
using AdventOfCodeLibrary._2023; using AdventOfCodeLibrary._2023;
using AdventOfCodeLibrary.Shared; using AdventOfCode.Core.Shared;
string _demoData = @"Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green string _demoData = @"Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green
Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue
@ -10,6 +10,9 @@ Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red
Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green"; Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green";
Answerable answerable = new Day02Part2(); Answerable answerable = new Day02Part2();
//FileStream stream = new FileStream(answerable.DefaultInputFile, new FileStreamOptions { Mode = FileMode.Open, Access = FileAccess.Read, Options = FileOptions.Asynchronous });
byte[] dataArray = File.ReadAllBytes(answerable.DefaultInputFile); byte[] dataArray = File.ReadAllBytes(answerable.DefaultInputFile);
//dataArray = Encoding.UTF8.GetBytes(_demoData); //dataArray = Encoding.UTF8.GetBytes(_demoData);

View File

@ -1,6 +1,5 @@
namespace AdventOfCodeLibrary._2022 namespace AdventOfCode.Solutions._2022
{ {
using AdventOfCodeLibrary.Shared;
public class Day01Part1 : Answerable public class Day01Part1 : Answerable
{ {

View File

@ -1,7 +1,5 @@
namespace AdventOfCodeLibrary._2022 namespace AdventOfCode.Solutions._2022
{ {
using AdventOfCodeLibrary.Shared;
public class Day01Part2 : Answerable public class Day01Part2 : Answerable
{ {
public override int Year { get; set; } = 2022; public override int Year { get; set; } = 2022;

View File

@ -1,8 +1,7 @@
namespace AdventOfCodeLibrary._2022 using AdventOfCode.Solutions._2022.Day02;
{
using AdventOfCodeLibrary._2022.Day02;
using AdventOfCodeLibrary.Shared;
namespace AdventOfCode.Solutions._2022
{
public class Day02Part1 : Answerable public class Day02Part1 : Answerable
{ {
public override int Year { get; set; } = 2022; public override int Year { get; set; } = 2022;

View File

@ -1,8 +1,7 @@
namespace AdventOfCodeLibrary._2022 using AdventOfCode.Solutions._2022.Day02;
{
using AdventOfCodeLibrary._2022.Day02;
using AdventOfCodeLibrary.Shared;
namespace AdventOfCode.Solutions._2022
{
public class Day02Part2 : Answerable public class Day02Part2 : Answerable
{ {
public override int Year { get; set; } = 2022; public override int Year { get; set; } = 2022;

View File

@ -1,4 +1,4 @@
namespace AdventOfCodeLibrary._2022.Day02 namespace AdventOfCode.Solutions._2022.Day02
{ {
internal class GameRules internal class GameRules
{ {

View File

@ -1,7 +1,5 @@
namespace AdventOfCodeLibrary._2022 namespace AdventOfCode.Solutions._2022
{ {
using AdventOfCodeLibrary.Shared;
public class Day03Part1 : Answerable public class Day03Part1 : Answerable
{ {
public override int Year { get; set; } = 2022; public override int Year { get; set; } = 2022;

View File

@ -1,7 +1,5 @@
namespace AdventOfCodeLibrary._2022 namespace AdventOfCode.Solutions._2022
{ {
using AdventOfCodeLibrary.Shared;
public class Day03Part2 : Answerable public class Day03Part2 : Answerable
{ {
public override int Year { get; set; } = 2022; public override int Year { get; set; } = 2022;

View File

@ -1,7 +1,5 @@
namespace AdventOfCodeLibrary._2022 namespace AdventOfCode.Solutions._2022
{ {
using AdventOfCodeLibrary.Shared;
public class Day04Part1 : Answerable public class Day04Part1 : Answerable
{ {
public override int Year { get; set; } = 2022; public override int Year { get; set; } = 2022;

View File

@ -1,7 +1,5 @@
namespace AdventOfCodeLibrary._2022 namespace AdventOfCode.Solutions._2022
{ {
using AdventOfCodeLibrary.Shared;
public class Day04Part2 : Answerable public class Day04Part2 : Answerable
{ {
public override int Year { get; set; } = 2022; public override int Year { get; set; } = 2022;

View File

@ -1,4 +1,4 @@
namespace AdventOfCodeLibrary._2022.Day_05 namespace AdventOfCode.Solutions._2022.Day_05
{ {
internal class CraneWork internal class CraneWork
{ {

View File

@ -1,8 +1,7 @@
namespace AdventOfCodeLibrary._2022 using AdventOfCode.Solutions._2022.Day_05;
{
using AdventOfCodeLibrary._2022.Day_05;
using AdventOfCodeLibrary.Shared;
namespace AdventOfCode.Solutions._2022
{
public class Day05Part1 : Answerable public class Day05Part1 : Answerable
{ {
public override int Year { get; set; } = 2022; public override int Year { get; set; } = 2022;

View File

@ -1,8 +1,7 @@
namespace AdventOfCodeLibrary._2022 using AdventOfCode.Solutions._2022.Day_05;
{
using AdventOfCodeLibrary._2022.Day_05;
using AdventOfCodeLibrary.Shared;
namespace AdventOfCode.Solutions._2022
{
public class Day05Part2 : Answerable public class Day05Part2 : Answerable
{ {
public override int Year { get; set; } = 2022; public override int Year { get; set; } = 2022;

View File

@ -1,7 +1,5 @@
namespace AdventOfCodeLibrary._2022 namespace AdventOfCode.Solutions._2022
{ {
using AdventOfCodeLibrary.Shared;
public class Day06Part1 : Answerable public class Day06Part1 : Answerable
{ {
public override int Year { get; set; } = 2022; public override int Year { get; set; } = 2022;

View File

@ -1,7 +1,5 @@
namespace AdventOfCodeLibrary._2022 namespace AdventOfCode.Solutions._2022
{ {
using AdventOfCodeLibrary.Shared;
public class Day06Part2 : Answerable public class Day06Part2 : Answerable
{ {
public override int Year { get; set; } = 2022; public override int Year { get; set; } = 2022;

View File

@ -1,8 +1,7 @@
namespace AdventOfCodeLibrary._2022 using AdventOfCode.Solutions._2022.Day_07;
{
using AdventOfCodeLibrary._2022.Day_07;
using AdventOfCodeLibrary.Shared;
namespace AdventOfCode.Solutions._2022
{
public class Day07Part1 : Answerable public class Day07Part1 : Answerable
{ {
public override int Year { get; set; } = 2022; public override int Year { get; set; } = 2022;

View File

@ -1,8 +1,7 @@
namespace AdventOfCodeLibrary._2022 using AdventOfCode.Solutions._2022.Day_07;
{
using AdventOfCodeLibrary._2022.Day_07;
using AdventOfCodeLibrary.Shared;
namespace AdventOfCode.Solutions._2022
{
public class Day07Part2 : Answerable public class Day07Part2 : Answerable
{ {
public override int Year { get; set; } = 2022; public override int Year { get; set; } = 2022;

View File

@ -1,4 +1,4 @@
namespace AdventOfCodeLibrary._2022.Day_07 namespace AdventOfCode.Solutions._2022.Day_07
{ {
public class Directory public class Directory
{ {

View File

@ -1,7 +1,5 @@
namespace AdventOfCodeLibrary._2022 namespace AdventOfCode.Solutions._2022
{ {
using AdventOfCodeLibrary.Shared;
public class Day08Part1 : Answerable public class Day08Part1 : Answerable
{ {
public override int Year { get; set; } = 2022; public override int Year { get; set; } = 2022;

View File

@ -1,7 +1,5 @@
namespace AdventOfCodeLibrary._2022 namespace AdventOfCode.Solutions._2022
{ {
using AdventOfCodeLibrary.Shared;
public class Day08Part2 : Answerable public class Day08Part2 : Answerable
{ {
public override int Year { get; set; } = 2022; public override int Year { get; set; } = 2022;

View File

@ -1,8 +1,7 @@
namespace AdventOfCodeLibrary._2022 using AdventOfCode.Solutions._2022.Day_09;
{
using AdventOfCodeLibrary._2022.Day_09;
using AdventOfCodeLibrary.Shared;
namespace AdventOfCode.Solutions._2022
{
public class Day09Part1 : Answerable public class Day09Part1 : Answerable
{ {
public override int Year { get; set; } = 2022; public override int Year { get; set; } = 2022;

View File

@ -1,8 +1,7 @@
namespace AdventOfCodeLibrary._2022 using AdventOfCode.Solutions._2022.Day_09;
{
using AdventOfCodeLibrary._2022.Day_09;
using AdventOfCodeLibrary.Shared;
namespace AdventOfCode.Solutions._2022
{
public class Day09Part2 : Answerable public class Day09Part2 : Answerable
{ {
public override int Year { get; set; } = 2022; public override int Year { get; set; } = 2022;

View File

@ -1,4 +1,4 @@
namespace AdventOfCodeLibrary._2022.Day_09 namespace AdventOfCode.Solutions._2022.Day_09
{ {
internal class VirtualPoint internal class VirtualPoint
{ {

View File

@ -1,7 +1,5 @@
namespace AdventOfCodeLibrary._2022 namespace AdventOfCode.Solutions._2022
{ {
using AdventOfCodeLibrary.Shared;
public class Day10Part1 : Answerable public class Day10Part1 : Answerable
{ {
public override int Year { get; set; } = 2022; public override int Year { get; set; } = 2022;

View File

@ -1,7 +1,5 @@
namespace AdventOfCodeLibrary._2022 namespace AdventOfCode.Solutions._2022
{ {
using AdventOfCodeLibrary.Shared;
public class Day10Part2 : Answerable public class Day10Part2 : Answerable
{ {
public override int Year { get; set; } = 2022; public override int Year { get; set; } = 2022;

View File

@ -1,8 +1,7 @@
namespace AdventOfCodeLibrary._2022 using AdventOfCode.Solutions._2022.Day_11;
{
using AdventOfCodeLibrary._2022.Day_11;
using AdventOfCodeLibrary.Shared;
namespace AdventOfCode.Solutions._2022
{
public class Day11Part1 : Answerable public class Day11Part1 : Answerable
{ {
public override int Year { get; set; } = 2022; public override int Year { get; set; } = 2022;

View File

@ -1,8 +1,7 @@
namespace AdventOfCodeLibrary._2022 using AdventOfCode.Solutions._2022.Day_11;
{
using AdventOfCodeLibrary._2022.Day_11;
using AdventOfCodeLibrary.Shared;
namespace AdventOfCode.Solutions._2022
{
public class Day11Part2 : Answerable public class Day11Part2 : Answerable
{ {
public override int Year { get; set; } = 2022; public override int Year { get; set; } = 2022;

View File

@ -1,4 +1,4 @@
namespace AdventOfCodeLibrary._2022.Day_11 namespace AdventOfCode.Solutions._2022.Day_11
{ {
internal class Monkey internal class Monkey
{ {

View File

@ -1,7 +1,5 @@
namespace AdventOfCodeLibrary._2022 namespace AdventOfCode.Solutions._2022
{ {
using AdventOfCodeLibrary.Shared;
public class Day12Part1 : Answerable public class Day12Part1 : Answerable
{ {
public override int Year { get; set; } = 2022; public override int Year { get; set; } = 2022;

View File

@ -1,7 +1,5 @@
namespace AdventOfCodeLibrary._2022 namespace AdventOfCode.Solutions._2022
{ {
using AdventOfCodeLibrary.Shared;
public class Day12Part2 : Answerable public class Day12Part2 : Answerable
{ {
public override int Year { get; set; } = 2022; public override int Year { get; set; } = 2022;

View File

@ -1,4 +1,4 @@
namespace AdventOfCodeLibrary._2022.Day_12 namespace AdventOfCode.Solutions._2022.Day_12
{ {
internal class Map internal class Map
{ {

View File

@ -1,9 +1,8 @@
namespace AdventOfCodeLibrary._2023 using System.Text.RegularExpressions;
{
using AdventOfCodeLibrary.Shared;
using System.Text.RegularExpressions;
public class Day01Part1 : Answerable namespace AdventOfCode.Solutions._2023
{
public class Day01Part1 : Answerable
{ {
public override int Year { get; set; } = 2023; public override int Year { get; set; } = 2023;
public override int Day { get; set; } = 1; public override int Day { get; set; } = 1;

View File

@ -1,8 +1,7 @@
namespace AdventOfCodeLibrary._2023 using System.Text.RegularExpressions;
{
using AdventOfCodeLibrary.Shared;
using System.Text.RegularExpressions;
namespace AdventOfCode.Solutions._2023
{
public class Day01Part2 : Answerable public class Day01Part2 : Answerable
{ {
public override int Year { get; set; } = 2023; public override int Year { get; set; } = 2023;

View File

@ -1,8 +1,7 @@
namespace AdventOfCodeLibrary._2023 using System.Text.RegularExpressions;
{
using AdventOfCodeLibrary.Shared;
using System.Text.RegularExpressions;
namespace AdventOfCode.Solutions._2023
{
public class Day02Part1 : Answerable public class Day02Part1 : Answerable
{ {
public override int Year { get; set; } = 2023; public override int Year { get; set; } = 2023;

View File

@ -1,8 +1,7 @@
namespace AdventOfCodeLibrary._2023 using System.Text.RegularExpressions;
{
using AdventOfCodeLibrary.Shared;
using System.Text.RegularExpressions;
namespace AdventOfCode.Solutions._2023
{
public class Day02Part2 : Answerable public class Day02Part2 : Answerable
{ {
public override int Year { get; set; } = 2023; public override int Year { get; set; } = 2023;

View File

@ -1,10 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net8.0</TargetFramework>
<RootNamespace>AdventOfCodeLibrary</RootNamespace> <RootNamespace>AdventOfCode.Solutions</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\AdventOfCode.Code\AdventOfCode.Core.csproj" />
</ItemGroup>
</Project> </Project>

View File

@ -0,0 +1 @@
global using AdventOfCode.Core.Shared;

View File

@ -5,7 +5,9 @@ VisualStudioVersion = 17.4.33103.184
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AdventOfCode.Runner", "Advend Of Code Runner\AdventOfCode.Runner.csproj", "{6DCDC513-AF72-4029-932A-A0079BB5422B}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AdventOfCode.Runner", "Advend Of Code Runner\AdventOfCode.Runner.csproj", "{6DCDC513-AF72-4029-932A-A0079BB5422B}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AdventOfCode.Library", "Advent Of Code Library\AdventOfCode.Library.csproj", "{33CC3924-F18E-4B88-9989-A7A9077B9AC4}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AdventOfCode.Solutions", "Advent Of Code Library\AdventOfCode.Solutions.csproj", "{33CC3924-F18E-4B88-9989-A7A9077B9AC4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdventOfCode.Core", "AdventOfCode.Code\AdventOfCode.Core.csproj", "{49EFF2F1-A5AD-448F-92EE-8CC95B2CECC2}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -21,6 +23,10 @@ Global
{33CC3924-F18E-4B88-9989-A7A9077B9AC4}.Debug|Any CPU.Build.0 = Debug|Any CPU {33CC3924-F18E-4B88-9989-A7A9077B9AC4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{33CC3924-F18E-4B88-9989-A7A9077B9AC4}.Release|Any CPU.ActiveCfg = Release|Any CPU {33CC3924-F18E-4B88-9989-A7A9077B9AC4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{33CC3924-F18E-4B88-9989-A7A9077B9AC4}.Release|Any CPU.Build.0 = Release|Any CPU {33CC3924-F18E-4B88-9989-A7A9077B9AC4}.Release|Any CPU.Build.0 = Release|Any CPU
{49EFF2F1-A5AD-448F-92EE-8CC95B2CECC2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{49EFF2F1-A5AD-448F-92EE-8CC95B2CECC2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{49EFF2F1-A5AD-448F-92EE-8CC95B2CECC2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{49EFF2F1-A5AD-448F-92EE-8CC95B2CECC2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,52 @@
using System.Runtime.InteropServices.Marshalling;
namespace AdventOfCode.Core
{
public class InputReader
{
private readonly string InputFileTemplate = "../../../../Advent Of Code Library/{1}/Day {2:00}/day-{2:00}-input.txt";
private int Day { get; set; }
private int Year { get; set; }
private string InputFilePath => string.Format(InputFileTemplate, Year, Day);
public void SetInputByChallange()
{
SetInputByChallange(DateTime.Now.Day, DateTime.Now.Year);
}
public void SetInputByChallange(int day)
{
SetInputByChallange(day, DateTime.Now.Year);
}
public void SetInputByChallange(int day, int year)
{
Day = day;
Year = year;
}
public async Task<string> ReadAsString() => await File.ReadAllTextAsync(InputFilePath);
public async IAsyncEnumerable<string> ReadAsStringLine()
{
using StreamReader reader = new(InputFilePath);
while (!reader.EndOfStream)
{
yield return (await reader.ReadLineAsync()) ?? string.Empty;
}
}
public async IAsyncEnumerable<T> ReadAsStringLine<T>(T emptyLineIndicator)
{
using StreamReader reader = new(InputFilePath);
while (!reader.EndOfStream)
{
string line = (await reader.ReadLineAsync()) ?? string.Empty;
if (string.IsNullOrWhiteSpace(line))
yield return emptyLineIndicator;
else
yield return (T)Convert.ChangeType(line, typeof(T));
}
}
}
}

View File

@ -1,4 +1,4 @@
namespace AdventOfCodeLibrary.Shared.A_Star namespace AdventOfCode.Core.Shared.A_Star
{ {
public class AStarGrid : Grid<AStarNode> public class AStarGrid : Grid<AStarNode>
{ {

View File

@ -1,4 +1,4 @@
namespace AdventOfCodeLibrary.Shared.A_Star namespace AdventOfCode.Core.Shared.A_Star
{ {
public class AStarNode : Node public class AStarNode : Node
{ {

View File

@ -1,6 +1,6 @@
using System.Text; using System.Text;
namespace AdventOfCodeLibrary.Shared namespace AdventOfCode.Core.Shared
{ {
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
@ -18,9 +18,9 @@ namespace AdventOfCodeLibrary.Shared
public abstract string GetAnswer(byte[] data); public abstract string GetAnswer(byte[] data);
internal static string GetAsString(byte[] bytes) => Encoding.UTF8.GetString(bytes).ReplaceLineEndings(); public static string GetAsString(byte[] bytes) => Encoding.UTF8.GetString(bytes).ReplaceLineEndings();
internal static string[] GetAsStringArray(byte[] bytes) => GetAsString(bytes).Split(NewLine).ToArray(); public static string[] GetAsStringArray(byte[] bytes) => GetAsString(bytes).Split(NewLine).ToArray();
private static string StripControlChars(string s) private static string StripControlChars(string s)
{ {

View File

@ -1,6 +1,6 @@
using System.Reflection; using System.Reflection;
namespace AdventOfCodeLibrary.Shared namespace AdventOfCode.Core.Shared
{ {
public class AnswerableListBuilder public class AnswerableListBuilder
{ {

View File

@ -1,6 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
namespace AdventOfCodeLibrary.Shared namespace AdventOfCode.Core.Shared
{ {
public class Grid<T> where T : Node public class Grid<T> where T : Node
{ {

View File

@ -1,4 +1,4 @@
namespace AdventOfCodeLibrary.Shared namespace AdventOfCode.Core.Shared
{ {
public class Node public class Node
{ {