diff --git a/AdvendOfCode.Runner/Program.cs b/AdvendOfCode.Runner/Program.cs index b1d5a15..df9e09e 100644 --- a/AdvendOfCode.Runner/Program.cs +++ b/AdvendOfCode.Runner/Program.cs @@ -7,9 +7,9 @@ InputReader inputReader = new() //IsDebug = true }; -//inputReader.SetInputByChallange(3); +inputReader.SetInputByChallange(6); -IChallange challange = new Day08(inputReader); +IChallange challange = new Day06(inputReader); Console.WriteLine($"Part 1: {await challange.GetSolutionPart1()}"); diff --git a/AdventOfCode.Solutions/2023/Day 06/Day06.cs b/AdventOfCode.Solutions/2023/Day 06/Day06.cs index d5b4953..0241fb4 100644 --- a/AdventOfCode.Solutions/2023/Day 06/Day06.cs +++ b/AdventOfCode.Solutions/2023/Day 06/Day06.cs @@ -1,19 +1,63 @@ using AdventOfCode.Core; +using System; +using System.Reflection; +using System.Text.RegularExpressions; namespace AdventOfCode.Solutions._2023 { - public class Day06(InputReader reader) : IChallange + public partial class Day06(InputReader reader) : IChallange { private InputReader _inputReader = reader; public async Task GetSolutionPart1() { - return string.Empty; + var data = (await _inputReader.ReadAsArrayString()).Select(line => GetDigets().Matches(line)).ToArray(); + long totalValue = 1; + for (int index = 0; index < data[0].Count; index++) + { + totalValue *= CalculateWays(int.Parse(data[0][index].Value), int.Parse(data[1][index].Value)); + } + + return totalValue.ToString(); } public async Task GetSolutionPart2() { - return string.Empty; + var data = (await _inputReader.ReadAsArrayString()).Select(line => GetDigets().Matches(line.Replace(" ", string.Empty))).ToArray(); + return CalculateWays(long.Parse(data[0][0].Value), long.Parse(data[1][0].Value)).ToString(); } + + private long CalculateWays(long raceTime, long currentDistance) + { + long distance, + waysToWin = 0, + time = raceTime; + if (raceTime % 2 == 1) + { + // uneven + time = (time + 1) / 2; + } + else + { + time /= 2; + time++; + waysToWin++; + } + + do + { + distance = time * (raceTime - time); + if (distance > currentDistance) + waysToWin += 2; + + time++; + } + while (distance > currentDistance); + + return waysToWin; + } + + [GeneratedRegex(@"\d+")] + private static partial Regex GetDigets(); } } \ No newline at end of file diff --git a/AdventOfCode.Solutions/2023/Day 07/Day07.cs b/AdventOfCode.Solutions/2023/Day 07/Day07.cs index 53895c3..1f10b6c 100644 --- a/AdventOfCode.Solutions/2023/Day 07/Day07.cs +++ b/AdventOfCode.Solutions/2023/Day 07/Day07.cs @@ -34,12 +34,8 @@ namespace AdventOfCode.Solutions._2023 { public int Bid { get; set; } public SetRanks Rank { get; set; } - public int HighValue { get; set; } - public string Source { get; set; } - public string JokerSource { get; set; } = string.Empty; - public List CharCompairList => string.IsNullOrEmpty(JokerSource) ? CardValues : CardValuesJoker; public Hand(string line, bool jokerMode = false) diff --git a/AdventOfCode.Solutions/day-00-input.txt b/AdventOfCode.Solutions/day-00-input.txt index a8e2c98..b39f49d 100644 --- a/AdventOfCode.Solutions/day-00-input.txt +++ b/AdventOfCode.Solutions/day-00-input.txt @@ -1,10 +1,2 @@ -LR - -11A = (11B, XXX) -11B = (XXX, 11Z) -11Z = (11B, XXX) -22A = (22B, XXX) -22B = (22C, 22C) -22C = (22Z, 22Z) -22Z = (22B, 22B) -XXX = (XXX, XXX) \ No newline at end of file +Time: 7 15 30 +Distance: 9 40 200 \ No newline at end of file