From ec973d77cf99d1fac50594a7ba77c6a62b3e0a16 Mon Sep 17 00:00:00 2001 From: Rob Date: Sun, 1 Dec 2024 10:17:24 +0100 Subject: [PATCH] Added actual new files.... --- AdvendOfCode.Runner/Program.cs | 6 +- AdventOfCode.Core/Shared/IO/IInputReader.cs | 31 + .../{ => Shared/IO}/InputReader.cs | 30 +- AdventOfCode.Core/SolutionManager.cs | 24 + AdventOfCode.Solutions/2023/Day 01/Day01.cs | 7 +- AdventOfCode.Solutions/2023/Day 02/Day02.cs | 7 +- AdventOfCode.Solutions/2023/Day 03/Day03.cs | 7 +- AdventOfCode.Solutions/2023/Day 04/Day04.cs | 8 +- AdventOfCode.Solutions/2023/Day 05/Day05.cs | 8 +- AdventOfCode.Solutions/2023/Day 06/Day06.cs | 7 +- AdventOfCode.Solutions/2023/Day 07/Day07.cs | 8 +- AdventOfCode.Solutions/2023/Day 08/Day08.cs | 7 +- AdventOfCode.Solutions/2023/Day 09/Day09.cs | 8 +- AdventOfCode.Solutions/2023/Day 10/Day10.cs | 8 +- AdventOfCode.Solutions/2023/Day 11/Day11.cs | 7 +- AdventOfCode.Solutions/2023/Day 12/Day12.cs | 8 +- AdventOfCode.Solutions/2023/Day 13/Day13.cs | 7 +- AdventOfCode.Solutions/2023/Day 14/Day14.cs | 7 +- AdventOfCode.Solutions/2023/Day 15/Day15.cs | 7 +- AdventOfCode.Solutions/2023/Day 16/Day16.cs | 8 +- AdventOfCode.Solutions/2023/Day 17/Day17.cs | 5 +- AdventOfCode.Solutions/2023/Day 18/Day18.cs | 8 +- AdventOfCode.Solutions/2023/Day 19/Day19.cs | 7 +- AdventOfCode.Solutions/2024/Day 01/Day01.cs | 69 ++ .../2024/Day 01/day-01-input.txt | 1000 +++++++++++++++++ AdventOfCode.Solutions/Day 00/Day00.cs | 28 + .../Day 00/day-00-input.txt | 0 .../ServiceConfiguration.cs | 23 + 28 files changed, 1278 insertions(+), 72 deletions(-) create mode 100644 AdventOfCode.Core/Shared/IO/IInputReader.cs rename AdventOfCode.Core/{ => Shared/IO}/InputReader.cs (85%) create mode 100644 AdventOfCode.Core/SolutionManager.cs create mode 100644 AdventOfCode.Solutions/2024/Day 01/Day01.cs create mode 100644 AdventOfCode.Solutions/2024/Day 01/day-01-input.txt create mode 100644 AdventOfCode.Solutions/Day 00/Day00.cs create mode 100644 AdventOfCode.Solutions/Day 00/day-00-input.txt create mode 100644 AdventOfCode.Solutions/ServiceConfiguration.cs diff --git a/AdvendOfCode.Runner/Program.cs b/AdvendOfCode.Runner/Program.cs index c2d34ce..8213ae2 100644 --- a/AdvendOfCode.Runner/Program.cs +++ b/AdvendOfCode.Runner/Program.cs @@ -1,8 +1,8 @@ using AdventOfCode.Solutions; using AdventOfCode.Core.Shared; -using AdventOfCode.Core; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.DependencyInjection; +using AdventOfCode.Core.Shared.IO; IChallange challange = Host.CreateDefaultBuilder() @@ -18,10 +18,8 @@ Console.WriteLine($"Part 2: {await challange.GetSolutionPart2()}"); static void ConfigureServices(IServiceCollection services) { - - services .AddChallanges() - .AddTransient() + .AddTransient() .AddScoped(); } \ No newline at end of file diff --git a/AdventOfCode.Core/Shared/IO/IInputReader.cs b/AdventOfCode.Core/Shared/IO/IInputReader.cs new file mode 100644 index 0000000..b965517 --- /dev/null +++ b/AdventOfCode.Core/Shared/IO/IInputReader.cs @@ -0,0 +1,31 @@ +using AdventOfCode.Core.Shared.Grid; + +namespace AdventOfCode.Core.Shared.IO +{ + public interface IInputReader + { + int Day { get; set; } + int Year { get; set; } + + void SetInput(IChallange challange); + + void SetInput(int day, int year); + + void SetSampleInput(bool isSample); + + Task ReadAsString(); + + IAsyncEnumerable ReadAsStringLine(); + Task ReadAsArrayString(); + + Task ReadAsVerticalArrayString(); + + IAsyncEnumerable ReadAsStringLine(T emptyLineIndicator); + + IAsyncEnumerable ReadLineAsLongArray(string seperator); + + Task> ReadToGrid() where T : Point, new(); + + IAsyncEnumerable> ReadToGrids() where T : Node, new(); + } +} diff --git a/AdventOfCode.Core/InputReader.cs b/AdventOfCode.Core/Shared/IO/InputReader.cs similarity index 85% rename from AdventOfCode.Core/InputReader.cs rename to AdventOfCode.Core/Shared/IO/InputReader.cs index 2f4ca09..0671a3f 100644 --- a/AdventOfCode.Core/InputReader.cs +++ b/AdventOfCode.Core/Shared/IO/InputReader.cs @@ -1,18 +1,17 @@ -using AdventOfCode.Core.Shared; -using AdventOfCode.Core.Shared.Grid; +using AdventOfCode.Core.Shared.Grid; -namespace AdventOfCode.Core +namespace AdventOfCode.Core.Shared.IO { - public class InputReader + public class LocalFileReader : IInputReader { private readonly string InputFileTemplate = "../../../../AdventOfCode.Solutions/{1}/Day {0:00}/day-{0:00}-input.txt"; private readonly string DebugInputFileTemplate = "../../../../AdventOfCode.Solutions/day-00-input.txt"; public bool IsDebug = false; - - private int Day { get; set; } - private int Year { get; set; } private string InputFilePath => IsDebug ? DebugInputFileTemplate : string.Format(InputFileTemplate, Day, Year); + public int Day { get; set; } + public int Year { get; set; } + public void SetInput(IChallange challange) { Day = challange.Day; @@ -25,6 +24,11 @@ namespace AdventOfCode.Core Year = year; } + public void SetSampleInput(bool isSample) + { + IsDebug = isSample; + } + public async Task ReadAsString() => await File.ReadAllTextAsync(InputFilePath); public async IAsyncEnumerable ReadAsStringLine() @@ -32,7 +36,7 @@ namespace AdventOfCode.Core using StreamReader reader = new(InputFilePath); while (!reader.EndOfStream) { - yield return (await reader.ReadLineAsync()) ?? string.Empty; + yield return await reader.ReadLineAsync() ?? string.Empty; } } @@ -51,14 +55,14 @@ namespace AdventOfCode.Core } return [.. result]; - } + } public async IAsyncEnumerable ReadAsStringLine(T emptyLineIndicator) { using StreamReader reader = new(InputFilePath); while (!reader.EndOfStream) { - string line = (await reader.ReadLineAsync()) ?? string.Empty; + string line = await reader.ReadLineAsync() ?? string.Empty; if (string.IsNullOrWhiteSpace(line)) yield return emptyLineIndicator; else @@ -71,7 +75,7 @@ namespace AdventOfCode.Core using StreamReader reader = new(InputFilePath); while (!reader.EndOfStream) { - string line = (await reader.ReadLineAsync()) ?? string.Empty; + string line = await reader.ReadLineAsync() ?? string.Empty; if (string.IsNullOrWhiteSpace(line)) yield return []; else @@ -83,7 +87,7 @@ namespace AdventOfCode.Core { Grid result = new(); int row = 0; - await foreach(string line in ReadAsStringLine()) + await foreach (string line in ReadAsStringLine()) { // create the nodes from the lines result.DataGrid.AddRange(line.Select((c, i) => new T { X = i, Y = row, Value = c })); @@ -114,5 +118,7 @@ namespace AdventOfCode.Core yield return result; yield break; } + + } } diff --git a/AdventOfCode.Core/SolutionManager.cs b/AdventOfCode.Core/SolutionManager.cs new file mode 100644 index 0000000..1c76256 --- /dev/null +++ b/AdventOfCode.Core/SolutionManager.cs @@ -0,0 +1,24 @@ +using AdventOfCode.Core.Shared; + +namespace AdventOfCode.Solutions +{ + public class SolutionManager + { + private readonly IChallange[] _challanges; + + public SolutionManager(IEnumerable challanges) + { + _challanges = challanges.ToArray(); + } + + public IEnumerable GetChallanges(Func predicate) + { + return _challanges.Where(predicate); + } + + public IChallange? GetChallange(int year, int day) + { + return _challanges.SingleOrDefault(challange => challange.Year == year && challange.Day == day); + } + } +} diff --git a/AdventOfCode.Solutions/2023/Day 01/Day01.cs b/AdventOfCode.Solutions/2023/Day 01/Day01.cs index 0cd59d3..0bcc066 100644 --- a/AdventOfCode.Solutions/2023/Day 01/Day01.cs +++ b/AdventOfCode.Solutions/2023/Day 01/Day01.cs @@ -1,4 +1,5 @@ -using System.Text.RegularExpressions; +using AdventOfCode.Core.Shared.IO; +using System.Text.RegularExpressions; namespace AdventOfCode.Solutions._2023 { @@ -8,9 +9,9 @@ namespace AdventOfCode.Solutions._2023 public int Day => 1; private readonly List NumberMapping = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]; - private readonly InputReader _inputReader; + private readonly IInputReader _inputReader; - public Day01(InputReader inputReader) + public Day01(IInputReader inputReader) { _inputReader = inputReader; _inputReader.SetInput(this); diff --git a/AdventOfCode.Solutions/2023/Day 02/Day02.cs b/AdventOfCode.Solutions/2023/Day 02/Day02.cs index 98680f3..2015fa1 100644 --- a/AdventOfCode.Solutions/2023/Day 02/Day02.cs +++ b/AdventOfCode.Solutions/2023/Day 02/Day02.cs @@ -1,4 +1,5 @@ -using System.Text.RegularExpressions; +using AdventOfCode.Core.Shared.IO; +using System.Text.RegularExpressions; namespace AdventOfCode.Solutions._2023 { @@ -7,9 +8,9 @@ namespace AdventOfCode.Solutions._2023 public int Year => 2023; public int Day => 2; - private readonly InputReader _inputReader; + private readonly IInputReader _inputReader; - public Day02(InputReader inputReader) + public Day02(IInputReader inputReader) { _inputReader = inputReader; _inputReader.SetInput(this); diff --git a/AdventOfCode.Solutions/2023/Day 03/Day03.cs b/AdventOfCode.Solutions/2023/Day 03/Day03.cs index e9b8926..2f179bf 100644 --- a/AdventOfCode.Solutions/2023/Day 03/Day03.cs +++ b/AdventOfCode.Solutions/2023/Day 03/Day03.cs @@ -1,4 +1,5 @@ -using System.Text.RegularExpressions; +using AdventOfCode.Core.Shared.IO; +using System.Text.RegularExpressions; namespace AdventOfCode.Solutions._2023 { @@ -7,9 +8,9 @@ namespace AdventOfCode.Solutions._2023 public int Year => 2023; public int Day => 3; - private readonly InputReader _inputReader; + private readonly IInputReader _inputReader; - public Day03(InputReader inputReader) + public Day03(IInputReader inputReader) { _inputReader = inputReader; _inputReader.SetInput(this); diff --git a/AdventOfCode.Solutions/2023/Day 04/Day04.cs b/AdventOfCode.Solutions/2023/Day 04/Day04.cs index 9b55feb..20f37d4 100644 --- a/AdventOfCode.Solutions/2023/Day 04/Day04.cs +++ b/AdventOfCode.Solutions/2023/Day 04/Day04.cs @@ -1,4 +1,6 @@ -namespace AdventOfCode.Solutions._2023 +using AdventOfCode.Core.Shared.IO; + +namespace AdventOfCode.Solutions._2023 { public class Day04 : IChallange { @@ -7,9 +9,9 @@ private Dictionary _cardRuns = new Dictionary { { 1, 1 } }; - private readonly InputReader _inputReader; + private readonly IInputReader _inputReader; - public Day04(InputReader inputReader) + public Day04(IInputReader inputReader) { _inputReader = inputReader; _inputReader.SetInput(this); diff --git a/AdventOfCode.Solutions/2023/Day 05/Day05.cs b/AdventOfCode.Solutions/2023/Day 05/Day05.cs index 4db3d0b..e3c5ed3 100644 --- a/AdventOfCode.Solutions/2023/Day 05/Day05.cs +++ b/AdventOfCode.Solutions/2023/Day 05/Day05.cs @@ -1,4 +1,6 @@ -namespace AdventOfCode.Solutions._2023 +using AdventOfCode.Core.Shared.IO; + +namespace AdventOfCode.Solutions._2023 { public class Day05 : IChallange { @@ -13,9 +15,9 @@ public const string TemperatureHumidity = "temperature-to-humidity map:"; public const string HumidityLocation = "humidity-to-location map:"; - private readonly InputReader _inputReader; + private readonly IInputReader _inputReader; - public Day05(InputReader inputReader) + public Day05(IInputReader inputReader) { _inputReader = inputReader; _inputReader.SetInput(this); diff --git a/AdventOfCode.Solutions/2023/Day 06/Day06.cs b/AdventOfCode.Solutions/2023/Day 06/Day06.cs index f8e0164..bd6b1bd 100644 --- a/AdventOfCode.Solutions/2023/Day 06/Day06.cs +++ b/AdventOfCode.Solutions/2023/Day 06/Day06.cs @@ -1,4 +1,5 @@ -using System.Text.RegularExpressions; +using AdventOfCode.Core.Shared.IO; +using System.Text.RegularExpressions; namespace AdventOfCode.Solutions._2023 { @@ -7,9 +8,9 @@ namespace AdventOfCode.Solutions._2023 public int Year => 2023; public int Day => 6; - private readonly InputReader _inputReader; + private readonly IInputReader _inputReader; - public Day06(InputReader inputReader) + public Day06(IInputReader inputReader) { _inputReader = inputReader; _inputReader.SetInput(this); diff --git a/AdventOfCode.Solutions/2023/Day 07/Day07.cs b/AdventOfCode.Solutions/2023/Day 07/Day07.cs index 6b10173..f8e2d9a 100644 --- a/AdventOfCode.Solutions/2023/Day 07/Day07.cs +++ b/AdventOfCode.Solutions/2023/Day 07/Day07.cs @@ -1,4 +1,6 @@ -namespace AdventOfCode.Solutions._2023 +using AdventOfCode.Core.Shared.IO; + +namespace AdventOfCode.Solutions._2023 { public class Day07 : IChallange { @@ -9,9 +11,9 @@ private static readonly List CardValuesJoker = ['J', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'Q', 'K', 'A']; private enum SetRanks { High, OnePair, TwoPair, ThreeKind, FullHouse, FourKind, FiveKind } - private readonly InputReader _inputReader; + private readonly IInputReader _inputReader; - public Day07(InputReader inputReader) + public Day07(IInputReader inputReader) { _inputReader = inputReader; _inputReader.SetInput(this); diff --git a/AdventOfCode.Solutions/2023/Day 08/Day08.cs b/AdventOfCode.Solutions/2023/Day 08/Day08.cs index 868b338..2bb7a66 100644 --- a/AdventOfCode.Solutions/2023/Day 08/Day08.cs +++ b/AdventOfCode.Solutions/2023/Day 08/Day08.cs @@ -1,4 +1,5 @@ -using System.Text.RegularExpressions; +using AdventOfCode.Core.Shared.IO; +using System.Text.RegularExpressions; namespace AdventOfCode.Solutions._2023 { @@ -7,9 +8,9 @@ namespace AdventOfCode.Solutions._2023 public int Year => 2023; public int Day => 8; - private readonly InputReader _inputReader; + private readonly IInputReader _inputReader; - public Day08(InputReader inputReader) + public Day08(IInputReader inputReader) { _inputReader = inputReader; _inputReader.SetInput(this); diff --git a/AdventOfCode.Solutions/2023/Day 09/Day09.cs b/AdventOfCode.Solutions/2023/Day 09/Day09.cs index 582cbba..7371657 100644 --- a/AdventOfCode.Solutions/2023/Day 09/Day09.cs +++ b/AdventOfCode.Solutions/2023/Day 09/Day09.cs @@ -1,13 +1,15 @@ -namespace AdventOfCode.Solutions._2023 +using AdventOfCode.Core.Shared.IO; + +namespace AdventOfCode.Solutions._2023 { public class Day09 : IChallange { public int Year => 2023; public int Day => 9; - private readonly InputReader _inputReader; + private readonly IInputReader _inputReader; - public Day09(InputReader inputReader) + public Day09(IInputReader inputReader) { _inputReader = inputReader; _inputReader.SetInput(this); diff --git a/AdventOfCode.Solutions/2023/Day 10/Day10.cs b/AdventOfCode.Solutions/2023/Day 10/Day10.cs index e2f1c19..3a1dccd 100644 --- a/AdventOfCode.Solutions/2023/Day 10/Day10.cs +++ b/AdventOfCode.Solutions/2023/Day 10/Day10.cs @@ -1,13 +1,15 @@ -namespace AdventOfCode.Solutions._2023 +using AdventOfCode.Core.Shared.IO; + +namespace AdventOfCode.Solutions._2023 { public class Day10 : IChallange { public int Year => 2023; public int Day => 10; - private readonly InputReader _inputReader; + private readonly IInputReader _inputReader; - public Day10(InputReader inputReader) + public Day10(IInputReader inputReader) { _inputReader = inputReader; _inputReader.SetInput(this); diff --git a/AdventOfCode.Solutions/2023/Day 11/Day11.cs b/AdventOfCode.Solutions/2023/Day 11/Day11.cs index 95adb5e..b485d60 100644 --- a/AdventOfCode.Solutions/2023/Day 11/Day11.cs +++ b/AdventOfCode.Solutions/2023/Day 11/Day11.cs @@ -1,4 +1,5 @@ -using System.Text.RegularExpressions; +using AdventOfCode.Core.Shared.IO; +using System.Text.RegularExpressions; namespace AdventOfCode.Solutions._2023 { @@ -7,9 +8,9 @@ namespace AdventOfCode.Solutions._2023 public int Year => 2023; public int Day => 11; - private readonly InputReader _inputReader; + private readonly IInputReader _inputReader; - public Day11(InputReader inputReader) + public Day11(IInputReader inputReader) { _inputReader = inputReader; _inputReader.SetInput(this); diff --git a/AdventOfCode.Solutions/2023/Day 12/Day12.cs b/AdventOfCode.Solutions/2023/Day 12/Day12.cs index ca7f736..0dbd5a6 100644 --- a/AdventOfCode.Solutions/2023/Day 12/Day12.cs +++ b/AdventOfCode.Solutions/2023/Day 12/Day12.cs @@ -1,13 +1,15 @@ -namespace AdventOfCode.Solutions._2023 +using AdventOfCode.Core.Shared.IO; + +namespace AdventOfCode.Solutions._2023 { public partial class Day12 : IChallange { public int Year => 2023; public int Day => 12; - private readonly InputReader _inputReader; + private readonly IInputReader _inputReader; - public Day12(InputReader inputReader) + public Day12(IInputReader inputReader) { _inputReader = inputReader; _inputReader.SetInput(this); diff --git a/AdventOfCode.Solutions/2023/Day 13/Day13.cs b/AdventOfCode.Solutions/2023/Day 13/Day13.cs index 798e743..06bfe2b 100644 --- a/AdventOfCode.Solutions/2023/Day 13/Day13.cs +++ b/AdventOfCode.Solutions/2023/Day 13/Day13.cs @@ -1,4 +1,5 @@ -using AdventOfCode.Solutions._2023.Day_13; +using AdventOfCode.Core.Shared.IO; +using AdventOfCode.Solutions._2023.Day_13; namespace AdventOfCode.Solutions._2023 { @@ -7,9 +8,9 @@ namespace AdventOfCode.Solutions._2023 public int Year => 2023; public int Day => 13; - private readonly InputReader _inputReader; + private readonly IInputReader _inputReader; - public Day13(InputReader inputReader) + public Day13(IInputReader inputReader) { _inputReader = inputReader; _inputReader.SetInput(this); diff --git a/AdventOfCode.Solutions/2023/Day 14/Day14.cs b/AdventOfCode.Solutions/2023/Day 14/Day14.cs index 45aae82..1c59c9f 100644 --- a/AdventOfCode.Solutions/2023/Day 14/Day14.cs +++ b/AdventOfCode.Solutions/2023/Day 14/Day14.cs @@ -1,4 +1,5 @@ -using System.Text; +using AdventOfCode.Core.Shared.IO; +using System.Text; namespace AdventOfCode.Solutions._2023 { @@ -7,9 +8,9 @@ namespace AdventOfCode.Solutions._2023 public int Year => 2023; public int Day => 14; - private readonly InputReader _inputReader; + private readonly IInputReader _inputReader; - public Day14(InputReader inputReader) + public Day14(IInputReader inputReader) { _inputReader = inputReader; _inputReader.SetInput(this); diff --git a/AdventOfCode.Solutions/2023/Day 15/Day15.cs b/AdventOfCode.Solutions/2023/Day 15/Day15.cs index 61382af..85dc4c5 100644 --- a/AdventOfCode.Solutions/2023/Day 15/Day15.cs +++ b/AdventOfCode.Solutions/2023/Day 15/Day15.cs @@ -1,4 +1,5 @@ -using System.Text; +using AdventOfCode.Core.Shared.IO; +using System.Text; namespace AdventOfCode.Solutions._2023 { @@ -7,9 +8,9 @@ namespace AdventOfCode.Solutions._2023 public int Year => 2023; public int Day => 15; - private readonly InputReader _inputReader; + private readonly IInputReader _inputReader; - public Day15(InputReader inputReader) + public Day15(IInputReader inputReader) { _inputReader = inputReader; _inputReader.SetInput(this); diff --git a/AdventOfCode.Solutions/2023/Day 16/Day16.cs b/AdventOfCode.Solutions/2023/Day 16/Day16.cs index ab12cf8..5ab10df 100644 --- a/AdventOfCode.Solutions/2023/Day 16/Day16.cs +++ b/AdventOfCode.Solutions/2023/Day 16/Day16.cs @@ -1,13 +1,15 @@ -namespace AdventOfCode.Solutions._2023 +using AdventOfCode.Core.Shared.IO; + +namespace AdventOfCode.Solutions._2023 { public class Day16 : IChallange { public int Year => 2023; public int Day => 16; - private readonly InputReader _inputReader; + private readonly IInputReader _inputReader; - public Day16(InputReader inputReader) + public Day16(IInputReader inputReader) { _inputReader = inputReader; _inputReader.SetInput(this); diff --git a/AdventOfCode.Solutions/2023/Day 17/Day17.cs b/AdventOfCode.Solutions/2023/Day 17/Day17.cs index 5a2e82a..56c6646 100644 --- a/AdventOfCode.Solutions/2023/Day 17/Day17.cs +++ b/AdventOfCode.Solutions/2023/Day 17/Day17.cs @@ -1,4 +1,5 @@ using AdventOfCode.Core.Shared.A_Star; +using AdventOfCode.Core.Shared.IO; namespace AdventOfCode.Solutions._2023 { @@ -7,9 +8,9 @@ namespace AdventOfCode.Solutions._2023 public int Year => 2023; public int Day => 17; - private readonly InputReader _inputReader; + private readonly IInputReader _inputReader; - public Day17(InputReader inputReader) + public Day17(IInputReader inputReader) { _inputReader = inputReader; _inputReader.SetInput(this); diff --git a/AdventOfCode.Solutions/2023/Day 18/Day18.cs b/AdventOfCode.Solutions/2023/Day 18/Day18.cs index d6af905..ac454a9 100644 --- a/AdventOfCode.Solutions/2023/Day 18/Day18.cs +++ b/AdventOfCode.Solutions/2023/Day 18/Day18.cs @@ -1,13 +1,15 @@ -namespace AdventOfCode.Solutions._2023 +using AdventOfCode.Core.Shared.IO; + +namespace AdventOfCode.Solutions._2023 { public class Day18 : IChallange { public int Year => 2023; public int Day => 18; - private readonly InputReader _inputReader; + private readonly IInputReader _inputReader; - public Day18(InputReader inputReader) + public Day18(IInputReader inputReader) { _inputReader = inputReader; _inputReader.SetInput(this); diff --git a/AdventOfCode.Solutions/2023/Day 19/Day19.cs b/AdventOfCode.Solutions/2023/Day 19/Day19.cs index c9b6fad..b289284 100644 --- a/AdventOfCode.Solutions/2023/Day 19/Day19.cs +++ b/AdventOfCode.Solutions/2023/Day 19/Day19.cs @@ -1,4 +1,5 @@ -using System.Text.RegularExpressions; +using AdventOfCode.Core.Shared.IO; +using System.Text.RegularExpressions; namespace AdventOfCode.Solutions._2023 { @@ -7,9 +8,9 @@ namespace AdventOfCode.Solutions._2023 public int Year => 2023; public int Day => 19; - private readonly InputReader _inputReader; + private readonly IInputReader _inputReader; - public Day19(InputReader inputReader) + public Day19(IInputReader inputReader) { _inputReader = inputReader; _inputReader.SetInput(this); diff --git a/AdventOfCode.Solutions/2024/Day 01/Day01.cs b/AdventOfCode.Solutions/2024/Day 01/Day01.cs new file mode 100644 index 0000000..a00f79c --- /dev/null +++ b/AdventOfCode.Solutions/2024/Day 01/Day01.cs @@ -0,0 +1,69 @@ +using AdventOfCode.Core.Shared.IO; + +namespace AdventOfCode.Solutions._2024 +{ + public class Day01 : IChallange + { + public int Year => 2024; + public int Day => 1; + + private readonly IInputReader _inputReader; + + public Day01(IInputReader inputReader) + { + _inputReader = inputReader; + _inputReader.SetInput(this); + } + + //11 + //1889772 + public async Task GetSolutionPart1() + { + int total = 0; + (List One, List Two) = await GetLists(); + + One = [.. One.Order()]; + Two = [.. Two.Order()]; + + for (int index = 0; index < One.Count; index++) { + int distance = Math.Abs(One[index] - Two[index]); + total += distance; + } + + return total.ToString(); + } + + //31 + //23228917 + public async Task GetSolutionPart2() + { + int total = 0; + (List One, List Two) = await GetLists(); + + var oneGroup = One.GroupBy(x => x); + var twoGroup = Two.GroupBy(x => x); + + foreach(var group in oneGroup) + { + var grouptwo = twoGroup.FirstOrDefault(g => g.Key == group.Key)?.Count() ?? 0; + total += group.Key * group.Count() * grouptwo; + } + + return total.ToString(); + } + + private async Task<(List One, List Two)> GetLists() + { + string[] data = await _inputReader.ReadAsArrayString(); + List one = [], two = []; + foreach (string s in data) + { + int[] numbers = s.Split(" ").Select(int.Parse).ToArray(); + one.Add(numbers[0]); + two.Add(numbers[1]); + } + + return (one, two); + } + } +} \ No newline at end of file diff --git a/AdventOfCode.Solutions/2024/Day 01/day-01-input.txt b/AdventOfCode.Solutions/2024/Day 01/day-01-input.txt new file mode 100644 index 0000000..35cf541 --- /dev/null +++ b/AdventOfCode.Solutions/2024/Day 01/day-01-input.txt @@ -0,0 +1,1000 @@ +66845 37619 +94793 99076 +76946 36179 +27374 48777 +47847 92154 +83270 97857 +19354 94331 +69716 58559 +16902 36957 +51817 88003 +40758 64262 +39074 90635 +34632 79874 +64980 96787 +96137 94559 +55489 98589 +95130 76776 +50275 50416 +46438 49722 +34182 49722 +99196 51678 +28426 49456 +55782 77278 +96554 38327 +92781 25688 +66818 64897 +83432 67261 +92511 85918 +87928 74826 +45552 37494 +60234 58251 +34717 40758 +17406 40666 +29863 13598 +30715 16605 +79985 24806 +19498 33371 +45577 59103 +22430 97187 +60651 52438 +24435 14715 +47805 33629 +21747 21255 +42759 37159 +81798 25688 +69888 75513 +10983 57175 +58312 51968 +86884 41517 +84419 46068 +18170 76776 +18387 30282 +30887 51117 +27509 49568 +79888 65951 +84877 31605 +37741 70988 +56232 51993 +66360 34958 +35077 60422 +11529 96255 +83449 21189 +65777 39047 +92759 70579 +36784 34261 +44166 77293 +27169 46068 +47337 15975 +58412 48777 +44195 71990 +86636 25688 +30002 64342 +92886 31836 +47608 76776 +93286 93216 +95162 72607 +28232 49722 +36024 42759 +79729 44744 +46188 90896 +36793 40758 +43516 69333 +20294 69351 +39704 65846 +12801 75185 +29338 69351 +87398 33648 +43037 40666 +48777 48777 +73934 51968 +63516 67431 +91790 94559 +86093 50924 +80995 95426 +18788 69351 +55112 58623 +50558 51968 +50125 48777 +70970 65082 +95693 34007 +17814 75466 +94946 34672 +28046 18149 +41708 92261 +94045 40666 +43687 64262 +61579 48777 +40428 60422 +22420 32085 +81816 40758 +46315 42253 +13240 48777 +14096 50416 +74231 98724 +65623 29631 +93360 51968 +23203 13106 +62141 96255 +78614 44089 +25431 25688 +40555 37905 +69148 67431 +59262 72776 +69333 40758 +44889 40666 +75646 80493 +96536 65674 +52772 55418 +89647 40758 +15843 14319 +96124 10675 +44307 65041 +26300 19974 +51312 78939 +80629 88003 +33658 72722 +82408 51968 +58384 40362 +96798 51968 +39019 64262 +53075 69333 +90232 81066 +70094 84299 +29829 64262 +22687 30237 +36509 31836 +65164 49722 +97198 73460 +94559 32258 +23976 75804 +68670 45453 +35761 33638 +89859 30972 +87196 48777 +93726 73290 +25588 40666 +82420 68892 +39195 66867 +18964 26674 +76776 45413 +81228 60422 +48337 92298 +35288 50416 +31186 94774 +62040 83156 +82769 40666 +75516 52772 +46916 83286 +77933 62114 +92256 68878 +32048 67431 +31355 92298 +81356 81828 +29014 64443 +40593 76965 +67982 92627 +57605 77293 +59621 23426 +71053 15293 +58788 33577 +96408 15826 +21328 16605 +60042 38036 +26150 16605 +36476 45576 +98875 26150 +50224 26150 +13099 77512 +24240 57493 +14259 36228 +25943 71801 +69018 15570 +64982 29117 +56462 42759 +18046 40666 +78056 26150 +34273 50416 +51578 73053 +28229 51968 +19334 81510 +74063 22991 +64637 99076 +63440 96255 +69596 90956 +44661 60422 +83603 73568 +47360 25240 +38361 56084 +30109 49115 +54979 49722 +57864 76776 +11404 23775 +31046 84459 +42983 63211 +82072 21091 +93495 31277 +14189 73053 +36367 50416 +99522 29631 +26894 44711 +20066 12397 +51211 69351 +75520 71791 +66473 41543 +41955 76776 +26371 45285 +73611 51968 +23686 46068 +85473 60422 +91840 30237 +64262 35142 +16860 48543 +89770 81829 +25598 48534 +80127 48777 +91437 23375 +68177 25777 +38952 90058 +24402 46233 +47962 16605 +35661 77293 +92555 69333 +46076 73053 +21462 50298 +77271 20126 +81010 71068 +22322 51968 +54671 16605 +42034 43993 +61234 16605 +11778 48777 +73064 96914 +92302 66267 +88810 39985 +28987 49722 +19948 63051 +46165 42759 +80483 32007 +10186 87088 +50266 98182 +38661 60422 +43071 29117 +29149 90127 +20786 92298 +41543 63002 +65554 44245 +38133 50446 +83184 43685 +81455 30237 +50181 20015 +21588 41543 +71901 77005 +56580 67190 +92298 30290 +12615 43868 +54771 97825 +40608 83376 +74661 81327 +74667 27063 +91093 69333 +78147 74050 +88520 67431 +83147 58241 +32466 96255 +88003 26594 +48870 44355 +57990 33895 +25924 52335 +28398 25688 +59394 16605 +88485 18070 +24797 94556 +20403 92298 +41703 25688 +98485 39009 +20982 71267 +89943 90424 +90090 84500 +48506 75682 +73724 15460 +16518 51968 +80097 85128 +17726 30691 +55319 76440 +31484 40758 +95079 69351 +51136 69333 +20432 50416 +36397 81701 +60587 87382 +97583 69333 +79660 79014 +90931 61415 +68754 99076 +81332 29631 +36693 18053 +83807 63785 +69967 41543 +42871 98738 +95094 91288 +99212 99076 +44058 84467 +80641 34674 +88334 29631 +88355 71891 +23565 64262 +64119 54463 +17173 36522 +28557 31472 +55707 49080 +60573 53380 +78740 48777 +25688 40758 +61756 50713 +42962 94559 +29631 92298 +94426 67431 +98512 82316 +68213 69351 +89436 29117 +52114 74278 +50779 18690 +37430 18749 +41985 87256 +18966 73331 +46251 69146 +77421 78181 +61790 45476 +74498 10793 +69841 82893 +65897 20462 +41449 29160 +48907 44418 +81437 40758 +59295 67431 +83332 89658 +72986 37494 +96096 50416 +61423 41543 +17994 96255 +61296 15425 +88163 59232 +54306 51570 +95733 61049 +99042 15221 +68770 71427 +88129 69333 +33732 92099 +77286 61983 +90425 60422 +15280 46859 +31735 70146 +52247 13562 +30396 40758 +99667 30237 +51830 79901 +83666 25524 +86580 98750 +85254 48777 +42725 11056 +23687 97931 +22760 94009 +46614 77846 +72811 24806 +54977 49722 +29431 73999 +18885 40666 +36487 64262 +89636 50324 +35161 49495 +81599 67431 +88407 33080 +22435 50416 +79005 10940 +57331 41543 +22158 40666 +96696 30237 +70561 45453 +73421 60631 +61118 43928 +42519 79091 +43521 64262 +63402 15989 +45694 95467 +76105 44778 +62478 68359 +12358 99076 +86440 88199 +87086 83286 +53389 39542 +85805 31836 +67650 68375 +15685 63010 +58192 46795 +47818 92298 +11074 94986 +71914 40666 +93767 14418 +15245 79805 +61703 69333 +98920 26347 +39398 43675 +24806 93670 +95455 83582 +31836 42759 +75823 89112 +76495 95693 +30421 64262 +29524 69542 +87652 26150 +28324 60422 +76379 22670 +21066 20848 +48616 71126 +27230 73053 +72632 73053 +68412 69333 +93254 71387 +58582 40758 +49794 41543 +47461 60562 +76885 14543 +64004 73230 +32657 96255 +53863 10455 +20628 35993 +91608 87804 +75577 69351 +71476 64262 +81995 23722 +50925 69351 +11299 77938 +35420 99076 +10331 29117 +15779 75594 +85678 37494 +91928 42759 +63346 75594 +66976 96255 +83382 88003 +57567 44223 +57699 13304 +87134 99196 +75545 76776 +25631 41543 +87276 10800 +56940 51968 +84938 42251 +95193 54917 +29270 34604 +89353 63191 +40688 42759 +66751 53340 +66452 16819 +38862 17153 +96222 46438 +87343 57690 +46164 57572 +99417 27010 +70060 10746 +71154 34499 +12509 48869 +93651 78940 +71299 73847 +10832 30237 +52974 64262 +40981 11346 +29705 40758 +67938 95118 +60177 49969 +47250 91132 +54643 25688 +85588 76776 +98925 69333 +60422 90370 +24036 39886 +29403 40758 +74173 25688 +55986 40758 +25014 69333 +12619 88003 +94185 66972 +36302 76776 +80587 47593 +69768 39980 +69155 11763 +50416 78224 +46304 16273 +96705 69351 +28345 35177 +77293 10590 +12724 52945 +35375 78625 +75160 45453 +46386 65833 +39994 48140 +91271 59925 +29612 77293 +41036 88472 +81721 69333 +17164 69333 +59045 55408 +47643 48777 +88393 31836 +84088 29471 +59047 99076 +78516 76776 +15157 99196 +43690 94559 +75594 53479 +44896 71111 +94548 39265 +83041 42184 +96815 51415 +32828 70721 +58699 81992 +31287 64262 +26029 37494 +65166 83286 +54211 99076 +83286 91733 +56093 73053 +72216 58645 +41450 27606 +40073 49722 +95257 78671 +45206 57288 +77156 16605 +95757 87915 +37072 43889 +64269 43521 +32134 94350 +17176 28044 +96935 16605 +12632 39455 +58840 64262 +45556 60422 +56436 23521 +63022 10638 +58109 65191 +20092 51968 +94565 87895 +95740 67431 +82012 14463 +95332 76776 +10057 36067 +90826 85685 +26656 37494 +21477 28483 +69198 30835 +86852 31534 +99374 40666 +67436 26735 +69091 37640 +98680 31836 +62432 46068 +81423 37494 +65121 49722 +63197 92795 +61748 89795 +48450 41543 +22248 50416 +53155 29214 +66777 83286 +61747 30639 +77640 31836 +30701 73053 +77911 39784 +68586 93617 +16193 95734 +87617 94302 +30286 81591 +37535 95903 +33511 95693 +13847 94086 +48968 92039 +18649 81319 +90213 51247 +19938 14934 +45563 77293 +65848 83368 +15964 74755 +46068 23448 +42958 13602 +75671 27217 +29655 51968 +22699 25688 +51147 42589 +94306 42759 +25877 30237 +65736 73053 +90797 16605 +37067 95623 +83464 91292 +42197 45801 +91306 99076 +60911 92298 +34318 33706 +38793 96334 +27850 37433 +14650 64262 +91128 64339 +32458 98055 +54600 62677 +98050 75988 +86045 41543 +42279 19215 +42179 41543 +74312 39080 +79748 67431 +40215 77293 +41710 90776 +30328 68060 +26336 88003 +36852 22273 +40112 16836 +85174 16605 +71517 32703 +67431 99004 +43343 64262 +13731 22989 +13807 54987 +67892 39600 +27164 13761 +73866 29117 +49004 11308 +30611 79799 +99434 64262 +39641 96255 +37656 46551 +31848 30237 +98478 83598 +98613 17687 +82739 36729 +90600 41659 +11405 52772 +38095 26098 +78900 49223 +90011 64515 +83200 65037 +71310 31350 +29261 29631 +99897 41543 +10080 60422 +53548 22585 +33783 94884 +13126 76776 +19067 48777 +60524 31565 +78024 69351 +78854 66750 +45049 47031 +99076 25688 +38748 81291 +10930 57953 +59839 26241 +78585 86796 +59376 49722 +60726 60127 +81844 97760 +53820 37832 +58200 51968 +39265 60422 +60470 33170 +91160 96442 +27028 85013 +47223 41543 +76737 16605 +57526 56760 +65236 31836 +53301 85609 +24915 16605 +35708 83286 +95380 27448 +84774 28106 +41172 68961 +91822 90839 +40133 50910 +12658 69351 +68683 61451 +48857 43558 +75612 40666 +68638 84502 +50216 77750 +99960 58184 +84452 13882 +45383 49722 +75492 60195 +13480 22237 +50803 84944 +54012 60422 +84902 96255 +17970 76776 +11010 86694 +99306 49722 +40510 64262 +49829 88882 +59557 60358 +85594 67431 +59545 67431 +20954 40666 +12472 78637 +70813 89650 +99797 81151 +77207 49160 +49923 51618 +65898 30237 +37494 24806 +85492 83863 +39497 37494 +36089 14785 +20089 42979 +96255 96255 +32410 46438 +48216 96255 +76597 54602 +53910 18651 +15354 14547 +98751 90551 +74557 90793 +86473 64457 +57086 86585 +69351 16557 +49032 10281 +95909 64037 +98841 26150 +38404 25688 +53132 48777 +41823 99294 +73232 16605 +14338 74560 +20654 61132 +39466 77293 +17828 99107 +44233 42759 +75537 82505 +97545 60422 +16764 51968 +17017 43797 +70260 61407 +85468 30237 +37966 64262 +49722 63390 +55689 41072 +47330 53047 +94724 60422 +28441 63752 +27435 25688 +49740 11717 +34057 27423 +64654 71907 +83242 29117 +97554 73053 +42324 69351 +43064 47040 +64801 40758 +55649 48777 +71147 41347 +90522 60422 +39447 28206 +26012 92655 +12500 21088 +96913 96255 +73053 21102 +96929 64262 +17234 49722 +71663 69333 +27255 61341 +20631 42759 +53872 89055 +21030 42759 +63642 92298 +37041 13379 +62151 99076 +44779 44361 +33142 70645 +34298 99076 +74521 71083 +97108 42956 +77170 40666 +82868 54524 +60362 38781 +66295 14324 +18853 92189 +86177 76776 +24054 49722 +64974 22099 +88395 26150 +24079 52772 +90673 26493 +28410 60422 +23503 41005 +22127 81692 +43022 69046 +21423 30237 +20584 99347 +19793 64262 +85494 29631 +35760 67431 +37390 11112 +11337 67225 +52314 25688 +99221 92298 +90131 76776 +79699 57892 +22197 89226 +21685 53250 +61808 13618 +95453 30237 +66322 46438 +49172 59373 +54628 40323 +87270 67431 +25855 69351 +18455 75737 +45453 75723 +48577 39690 +47391 56849 +32796 55399 +36667 27839 +24640 92298 +52237 62652 +10472 65480 +96200 40686 +48162 27800 +31265 87629 +28125 99076 +73922 90954 +32255 48777 +47397 73220 +47401 38154 +70327 60422 +38692 19213 +18472 31836 +71218 35466 +37097 33313 +79607 49008 +88691 16605 +30767 19624 +47670 88003 +87223 15008 +62459 74801 +35995 76776 +39905 51968 +62948 16651 +14137 97229 +51968 25688 +19454 77293 +48128 29631 +87280 46179 +97139 29631 +91913 51492 +52926 66255 +88930 41045 +51402 13749 +56326 16605 +56973 31836 +30330 40666 +56823 39962 +43407 69225 +86434 45453 +16605 27225 +24931 27332 +58345 67854 +25412 61629 +90343 95693 +20577 84501 +19871 64775 +33550 73053 +30768 48777 +44985 96255 +93435 69530 +17474 83436 +33032 27464 +67655 77293 +11189 25688 +76696 29631 +81827 37289 +14652 41543 +78881 35379 +49434 40758 +16136 37494 +95899 99076 +52886 49722 +75680 59071 +25008 18424 +10532 45453 +70853 67108 +97765 41543 +77075 98528 +49731 45588 +12421 81360 +13995 20115 +13459 67635 +44822 20506 +45941 40758 +84375 46068 +68154 27538 +50838 85083 +57673 43557 +89564 10626 +86616 45453 +95622 16605 +95036 38065 +69957 76776 +68179 32072 +11978 23791 +89856 12649 +43029 33383 +30680 91350 +65119 51344 +61868 77293 +28887 89141 +30237 92298 +74565 45124 +52029 51153 +53311 81204 +28179 45453 +25996 67537 +21527 88003 +40311 88003 +77116 64262 +32339 43982 +51922 52772 +39858 41543 +42050 33920 +22499 40777 +40666 75657 +49779 48777 +57894 34518 +21691 67431 +29904 25688 +73894 79235 +25080 47224 +24284 41543 +62787 58837 +82576 96255 +90992 21575 +56542 25688 +93368 48777 +97106 96422 +95744 75594 +86470 42303 +15426 92298 +67124 29117 +93975 80395 +20387 57449 +98213 31836 +58271 60721 +26911 48788 +18479 99076 +10735 49722 +27321 42759 +49224 16605 +38905 45630 +81499 15623 +50470 29434 +25745 41944 +85084 95159 +36196 67431 +43825 42915 +11678 14222 +63510 72474 +15304 52772 +13540 25688 +95310 40758 +64421 88003 +14821 76776 +29117 89841 +22026 33570 +66744 36521 +73205 72863 +13305 60422 +47886 15634 +16515 59541 +86124 77004 +30895 46438 +69966 25582 +31783 85509 +97288 51968 \ No newline at end of file diff --git a/AdventOfCode.Solutions/Day 00/Day00.cs b/AdventOfCode.Solutions/Day 00/Day00.cs new file mode 100644 index 0000000..7a05a91 --- /dev/null +++ b/AdventOfCode.Solutions/Day 00/Day00.cs @@ -0,0 +1,28 @@ +using AdventOfCode.Core.Shared.IO; + +namespace AdventOfCode.Solutions._2023 +{ + public class Day00 : IChallange + { + public int Year => 0; + + public int Day => 0; + + private readonly InputReader _inputReader; + + public Day00(InputReader inputReader) + { + _inputReader = inputReader; + _inputReader.SetInput(this); + } + public async Task GetSolutionPart1() + { + return string.Empty; + } + + public async Task GetSolutionPart2() + { + return string.Empty; + } + } +} \ No newline at end of file diff --git a/AdventOfCode.Solutions/Day 00/day-00-input.txt b/AdventOfCode.Solutions/Day 00/day-00-input.txt new file mode 100644 index 0000000..e69de29 diff --git a/AdventOfCode.Solutions/ServiceConfiguration.cs b/AdventOfCode.Solutions/ServiceConfiguration.cs new file mode 100644 index 0000000..41b8a90 --- /dev/null +++ b/AdventOfCode.Solutions/ServiceConfiguration.cs @@ -0,0 +1,23 @@ +using AdventOfCode.Solutions._2024; +using Microsoft.Extensions.DependencyInjection; + +namespace AdventOfCode.Solutions +{ + public static class ServiceConfiguration + { + public static IServiceCollection AddChallanges(this IServiceCollection services) + { + IEnumerable challanges = AppDomain.CurrentDomain.GetAssemblies().SelectMany(a => a.GetTypes()) + .Where(t => t.GetInterfaces().Contains(typeof(IChallange))); + + services.AddScoped(); + + //foreach (Type challange in challanges) + //{ + // services.AddScoped(typeof(IChallange), challange); + //} + + return services; + } + } +}