diff --git a/AdvendOfCode.Runner/Program.cs b/AdvendOfCode.Runner/Program.cs index d5e4b71..15726af 100644 --- a/AdvendOfCode.Runner/Program.cs +++ b/AdvendOfCode.Runner/Program.cs @@ -6,7 +6,10 @@ InputReader inputReader = new() { //IsDebug = true }; -IChallange challange = new Day04(inputReader); + +inputReader.SetInputByChallange(2); + +IChallange challange = new Day02(inputReader); Console.WriteLine($"Part 1: {await challange.GetSolutionPart1()}"); diff --git a/AdventOfCode.Core/InputReader.cs b/AdventOfCode.Core/InputReader.cs index 3ec7095..34ab196 100644 --- a/AdventOfCode.Core/InputReader.cs +++ b/AdventOfCode.Core/InputReader.cs @@ -42,7 +42,7 @@ namespace AdventOfCode.Core } } - public Task ReadAsArraytString() + public Task ReadAsArrayString() { return File.ReadAllLinesAsync(InputFilePath); } diff --git a/AdventOfCode.Solutions/2023/Day 01/Day01Part1.cs b/AdventOfCode.Solutions/2023/Day 01/Day01Part1.cs deleted file mode 100644 index b41450a..0000000 --- a/AdventOfCode.Solutions/2023/Day 01/Day01Part1.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.Text.RegularExpressions; - -namespace AdventOfCode.Solutions._2023 -{ -public class Day01Part1 : Answerable - { - public override int Year { get; set; } = 2023; - public override int Day { get; set; } = 1; - public override int Part { get; set; } = 1; - - public override string GetAnswer(byte[] data) - { - return GetAsStringArray(data) - .Select(GetValueFromLine) - .Sum() - .ToString(); - } - - private int GetValueFromLine(string line) - { - // get all the numers - MatchCollection collection = Regex.Matches(line, @"\d"); - - // merge first and last index as one - string values = collection[0].Value + collection[^1].Value; - - // make an int - return int.Parse(values); - } - } -} diff --git a/AdventOfCode.Solutions/2023/Day 01/Day01Part2.cs b/AdventOfCode.Solutions/2023/Day 01/Day01Part2.cs deleted file mode 100644 index 239cff7..0000000 --- a/AdventOfCode.Solutions/2023/Day 01/Day01Part2.cs +++ /dev/null @@ -1,79 +0,0 @@ -using System.Text.RegularExpressions; - -namespace AdventOfCode.Solutions._2023 -{ - public class Day01Part2 : Answerable - { - public override int Year { get; set; } = 2023; - public override int Day { get; set; } = 1; - public override int Part { get; set; } = 2; - - public override string GetAnswer(byte[] data) - { - return GetAsStringArray(data) - .Select(GetValueFromLine) - .Sum() - .ToString(); - } - - private int GetValueFromLine(string line) - { - MatchCollection matchCollection = Regex.Matches(line, @"(\d)"); - List captures = matchCollection.ToList(); - - // replace the text with numbers - captures.AddRange(Regex.Matches(line, @"(one)")); - captures.AddRange(Regex.Matches(line, @"(two)")); - captures.AddRange(Regex.Matches(line, @"(three)")); - captures.AddRange(Regex.Matches(line, @"(four)")); - captures.AddRange(Regex.Matches(line, @"(five)")); - captures.AddRange(Regex.Matches(line, @"(six)")); - captures.AddRange(Regex.Matches(line, @"(seven)")); - captures.AddRange(Regex.Matches(line, @"(eight)")); - captures.AddRange(Regex.Matches(line, @"(nine)")); - - captures = captures.OrderBy(x => x.Index).ToList(); - - // merge first and last index as one - string values = GetStringAsNumber(captures.First().Value) + GetStringAsNumber(captures.Last().Value); - // make an int - return int.Parse(values); - } - - private string GetStringAsNumber(string value) - { - switch(value) - { - case "one": - case "1": - return "1"; - case "two": - case "2": - return "2"; - case "three": - case "3": - return "3"; - case "four": - case "4": - return "4"; - case "five": - case "5": - return "5"; - case "six": - case "6": - return "6"; - case "seven": - case "7": - return "7"; - case "eight": - case "8": - return "8"; - case "nine": - case "9": - return "9"; - default: - return string.Empty; - } - } - } -} diff --git a/AdventOfCode.Solutions/2023/Day 02/Day02Part1.cs b/AdventOfCode.Solutions/2023/Day 02/Day02Part1.cs deleted file mode 100644 index 1ac7f20..0000000 --- a/AdventOfCode.Solutions/2023/Day 02/Day02Part1.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System.Text.RegularExpressions; - -namespace AdventOfCode.Solutions._2023 -{ - public class Day02Part1 : Answerable - { - public override int Year { get; set; } = 2023; - public override int Day { get; set; } = 2; - public override int Part { get; set; } = 1; - - public override string GetAnswer(byte[] data) - { - return GetAsStringArray(data) - .Select(ParseGames) - .Sum() - .ToString(); - } - - private int ParseGames(string line) - { - // get all the numers - string gameId = line.Split(':')[0].Split(' ')[1]; - string[] dicePulls = line.Split(':')[1].Split(';'); - - // parse the pulls - foreach (string dicePull in dicePulls) - { - // regex the pull - MatchCollection dice = Regex.Matches(dicePull, "(\\d+) (g|r|b)"); - foreach (Match match in dice) - { - string[] splitted = match.Value.Split(' '); - int ammount = int.Parse(splitted[0]); - - if (ammount <= 12) // pass for all dice - continue; - - if (ammount > 14 // fail for any dice set - || (splitted[1] == "r" && ammount > 12) - || (splitted[1] == "g" && ammount > 13)) - return 0; // not possible - } - - } - - return int.Parse(gameId); - } - } -} \ No newline at end of file diff --git a/AdventOfCode.Solutions/2023/Day 02/Day02Part2.cs b/AdventOfCode.Solutions/2023/Day 02/Day02Part2.cs deleted file mode 100644 index 4262477..0000000 --- a/AdventOfCode.Solutions/2023/Day 02/Day02Part2.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System.Text.RegularExpressions; - -namespace AdventOfCode.Solutions._2023 -{ - public class Day02Part2 : Answerable - { - public override int Year { get; set; } = 2023; - public override int Day { get; set; } = 2; - public override int Part { get; set; } = 2; - - public override string GetAnswer(byte[] data) - { - return GetAsStringArray(data) - .Select(GetValueFromLine) - .Sum() - .ToString(); - } - - private int GetValueFromLine(string line) - { - // get all the numers - string dicePulls = line.Split(':')[1]; - - // parse the pulls - MatchCollection dice = Regex.Matches(dicePulls, "(\\d+) (g|r|b)"); - int red = 0, green = 0, blue = 0; - foreach (Match match in dice) - { - string[] splitted = match.Value.Split(' '); - int ammount = int.Parse(splitted[0]); - - if (splitted[1] == "r" && ammount > red) { red = ammount; } - else if (splitted[1] == "g" && ammount > green) { green = ammount; } - else if (splitted[1] == "b" && ammount > blue) { blue = ammount; } - } - - - return red * green * blue; - } - } -} diff --git a/AdventOfCode.Solutions/AdventOfCode.Solutions.csproj b/AdventOfCode.Solutions/AdventOfCode.Solutions.csproj index 1b3af41..087dc16 100644 --- a/AdventOfCode.Solutions/AdventOfCode.Solutions.csproj +++ b/AdventOfCode.Solutions/AdventOfCode.Solutions.csproj @@ -12,6 +12,12 @@ + + Always + + + Always + Always