diff --git a/AdvendOfCode.Runner/Program.cs b/AdvendOfCode.Runner/Program.cs index 2f29638..3fa7eb9 100644 --- a/AdvendOfCode.Runner/Program.cs +++ b/AdvendOfCode.Runner/Program.cs @@ -10,7 +10,7 @@ IChallange challange = Host.CreateDefaultBuilder() .Build() .Services .GetService() - .GetChallange(2024, 5); + .GetChallange(2024, 6); Console.WriteLine($"Part 1: {await challange.GetSolutionPart1()}"); diff --git a/AdventOfCode.Solutions/2024/Day 06/Day06.cs b/AdventOfCode.Solutions/2024/Day 06/Day06.cs new file mode 100644 index 0000000..b6444f9 --- /dev/null +++ b/AdventOfCode.Solutions/2024/Day 06/Day06.cs @@ -0,0 +1,93 @@ +using AdventOfCode.Core.Shared.IO; + +namespace AdventOfCode.Solutions._2024 +{ + public class Day06 : IChallange + { + public int Year => 2024; + + public int Day => 6; + + private readonly IInputReader _inputReader; + + public Day06(IInputReader inputReader) + { + _inputReader = inputReader; + _inputReader.SetInput(this); + //_inputReader.SetSampleInput(true); + } + + // 41 + // 4696 + public async Task GetSolutionPart1() + { + Grid map = await _inputReader.ReadToGrid(); + Point current = map.DataGrid.Single(p => p.Value == '^'); + HashSet points = [current]; + Point move = new Point(0, -1); + + do + { + // check if we are done + long nextX = current.X + move.X, + nextY = current.Y + move.Y; + if (nextX == -1 || nextX == map.Columns + || nextY == -1 || nextY == map.Rows) + break; + + // get next + Point next = map.GetNode(nextX, nextY); + if (next.Value == '#') + { + move = Turn(move); + //Console.WriteLine("turned " + move.ToString()); + continue; + } + + points.Add(next); + current = next; + //Console.WriteLine("moved " + current.ToString()); + } + while (true); + + return points.Count.ToString(); + } + + // 6 + // + public async Task GetSolutionPart2() + { + return string.Empty; + } + + private Point Turn(Point currentDir) + { + if (currentDir.Y == -1 && currentDir.X == 0) + { + currentDir.Y = 0; + currentDir.X = 1; + return currentDir; + } + else if (currentDir.Y == 0 && currentDir.X == 1) + { + currentDir.Y = 1; + currentDir.X = 0; + return currentDir; + } + else if (currentDir.Y == 1 && currentDir.X == 0) + { + currentDir.Y = 0; + currentDir.X = -1; + return currentDir; + } + else if(currentDir.Y == 0 && currentDir.X == -1) + { + currentDir.Y = -1; + currentDir.X = 0; + return currentDir; + } + + throw new InvalidDataException(); + } + } +} \ No newline at end of file diff --git a/AdventOfCode.Solutions/2024/Day 06/day-06-input.txt b/AdventOfCode.Solutions/2024/Day 06/day-06-input.txt new file mode 100644 index 0000000..f62cc25 --- /dev/null +++ b/AdventOfCode.Solutions/2024/Day 06/day-06-input.txt @@ -0,0 +1,130 @@ +.#......................................#................#....#.......##..........................#.....#......#.................. +......#...#...................................#......#...#........#...........................................#.#................. +.....................................................#.......#.............#................#...............#...#...........#..... +..........#...#.......#...........#.......................................#..............#.......#.#......#...............#....... +...#.......................................................................#.................................................#.... +.......#.....#................#.......#..................#......#...........#...............................#..................... +.........#.......#..#...........................#........#.........................#..#.....#..................................... +..........#.......##....................#..............##..##..#...#........................................................#..... +................#............................................................#.......................#...#........................ +...............................................................................................#...........................#...... +#.....#..............#...............#.........#................................................................#........#........ +.....#..#.................................#......................................................................#................ +............................................#..................................................................................... +.............#....................................#.................#...##........#....#....#..................................... +.............#.............#...........##..............#.........#....#................#....................#..................... +..#..#...#.............#....................................#.........................................................#........... +........................#......#...........#.....#....................#.........................#................................. +.................#................................................................................................................ +.........#.......#..........#...............#................................#........................#.........#......#.......... +.........................................#.........#..........#.........#........................#......................#......... +.#.....................#.............................#.....................#.............................................#........ +...#..#........#...............#......................#..................#........................................#...#........... +..#...........#..........#......#...............#...............................................................#................. +......#..#.............................#.#..............#......#.................................................................. +......#..........#....#...#.........#...................................................................#...........#............. +............#....#.....#..............................................#.......#..............#........................#........... +......#.................#...............................................................................#...................#..... +................#................#............................................................................#.....##............ +.........#......................................#....#......#.......................................#........##..........#........ +#........#.........................................#..........#..............#.......#............................................ +.#..........##....................#......................................................................#................#..#.... +...........................................#............................#..........................#....................#......... +......#.......................#.............#......................................................................#.............. +..#.#.....#...#....#....#......#..................................#...................#........................................... +..#................................#...................................#...#..................................#.......#........... +....#...............#....................................#..#..............#.........#.........#.#..............................#. +..........#......#.........................#.#.................................#...........................................#.....# +..................##.................#...........#................................#.............................................#. +.....#......#................#....................................................#..............#.........................#...... +#..............#........#..............................#...........#...............#.....#.............................#.......... +..............#.........................#........................................................#..........................#..##. +...............................................................#..............................................#................... +......................#.............................................................##.........#...........................#.#.... +.......#................................#................#...........................#...................#.........#.............. +.................................................................#...#.............#.....#...............#........................ +..............................................................#..#...............................#.......#...............#.#...... +.....#.................#......................#..........................................#........................................ +..............................#...............#......#..........#........................#................#......#................ +.............................................#.........#..................................................................#....... +......#..........................#.............#....................................................#................#............ +..................#..............................................#..........................................#..................... +..#.........................................#..............................#...#........................................#..#...... +........#........................#................................................................................................ +...............#...............................#.............#...........................#........................................ +...............................................................................................#....#............................. +............#.....................#...........#.............#.......#..............#.....#.............................#...#...... +..........#..........................................................#.#.......#.................................................. +...#................................#.....................................................................#...................#... +...#..#...........................#............................#........#.......#.#..........#.......#............................ +...................##......................................#..................##..............................#........#.......... +................##.....................................................................#....................................#..... +....#......................................................#..............#....#.................................#................ +......................#...#............................................................................................#.......... +..#......................#.................................................#.....#.....................................##......... +....................##.......................#............#.#....#......#...........#.............#..#................#...#....##. +.....................................................................................#....#..........#............................ +..................#...............................................#.....#..#............#.....................##.............#.... +......#.................................................................#.....#........#..#....................................... +......#..............................................#........#................#.................................................. +........#........#...........#....................#...............................#..........................................#.... +.##............................................................#............#..............................................#...... +........................#............................#.....#....................#............#.................................... +...#......#.............#..#..#........#...............................................................................#..#....#.. +#.....#...............................................#...#....#................#....#....................................#....... +.................................#..#...........................................................................................#. +..........#.........................#.....................#............................................#.......................... +..............................#........#...................................#..#................................#...#.............# +...#....................#.............................#..............................#..#..#...................................... +..........#...................#....................#.....##............................#.....................#.................... +.................#..........#.........................##.....................................................#.........#.......... +..........................................................#....................................#..........#....................... +.........................................................#.....#..#.................#..............................#.............. +................#..................#...............#.............#......#............#.................#...................##..... +...................#.....#...............................#.................................#.........##........................... +......................#..........#..........#...................................#..............#......#........................... +...........................................................#......#...#.....................#.....#.......................#....#.. +.....................#.........................#.......#.........#................................#.#....................#......#. +...............................#..............................................#......#.................................#........#. +........#...........................................#...#.........................................#.........................#..#.. +..............#............................#.....#.....#.......#...^...........................#................#.........#....... +..........#.#..............#.........#.............#............................................................#................. +.......#..#......#.......................................................................#........................................ +..........#..........................##.............#.....#..........#.............................................#.............. +................#............#.....#................#....#......................................................#........#........ +..#......................##.......................##.....#.....#.............................................#.................... +....#...........#.................................................##........................#...#..#.............................. +...........#..........................#..........................................#...#............................................ +##......#.........#...........#...#................................##................#...................##......#................ +.....................#...............#.............#..........#.#..................#....................#.......#................. +...#..#.....#............#.....#......#.#......................................................................................... +...#..............................................................................................................#.........#..... +..................#..........................#.................................................#.................................. +..........#...................................#.......#..#.....#.................#............##.#......#........#...#............ +.......#....#............................................................................#.......................#................ +.......................#...................#..#.......#..#.............#................#......................................... +........#......................#.......#...........#......##................##..#......#.#....#........#.......................... +...#..................................#........................#.....#..#......................................................... +..#.......#...........#.........#.##..........#...........................................#...........................#........... +...................#........................................#...........#.................#.#......................#.#............ +#......................#.............................#................................#.............#....#...........#............ +.........#...........................................#.....#......................................#.......................#....... +.......................#.#...............................#........................................................................ +...........................#...............................................................#..............#....................... +.......##..................#..........#......#.....................#.#.............................##..#.................#........ +#.#...........#..........................................................#.....#...##......#......................#..#............ +..#.............................#................#.#.........##..........................................................#........ +.......................................#.......................................#...#.........#.............#...................... +....#.##................................................#....................................................#.#...........#...... +...#............................#.....#............#..................................#..........................................# +.........#...#..................................#.................#................................#...#.......................... +.....................................#.............................#...#..........#.................#........#.......#............ +.........##........#.#.....................................................................................................#...... +...............................#....#.......#............#......#...................................#...............#............. +....##.#.............................##..........#....#...................#..........................#......#.#.#................. +............#.........#.....#..............................#...................................................................... +..........#...#...#.......................#.............#...................#.##.......#.................#......#................. +..#..#..#...............................#.............#.................................................................#...#..... +.......................#..#.......................#..............#............#..........#........#..............................# +.....#...............#...##...........#..................#........................................#.....#.....#................... +....#.....................................#..........#..........#..#.....#...#....#...#...............#..........................# \ No newline at end of file diff --git a/AdventOfCode.Solutions/AdventOfCode.Solutions.csproj b/AdventOfCode.Solutions/AdventOfCode.Solutions.csproj index c4322b4..9af0705 100644 --- a/AdventOfCode.Solutions/AdventOfCode.Solutions.csproj +++ b/AdventOfCode.Solutions/AdventOfCode.Solutions.csproj @@ -34,6 +34,9 @@ Always + + Always + Always diff --git a/AdventOfCode.Solutions/Day 00/Day00.cs b/AdventOfCode.Solutions/Day 00/Day00.cs index 56e61af..142f118 100644 --- a/AdventOfCode.Solutions/Day 00/Day00.cs +++ b/AdventOfCode.Solutions/Day 00/Day00.cs @@ -1,6 +1,6 @@ using AdventOfCode.Core.Shared.IO; -namespace AdventOfCode.Solutions._2024 +namespace AdventOfCode.Solutions { public class Day00 : IChallange { @@ -13,6 +13,7 @@ namespace AdventOfCode.Solutions._2024 public Day00(IInputReader inputReader) { _inputReader = inputReader; + _inputReader.SetInput(this); } public async Task GetSolutionPart1() { diff --git a/AdventOfCode.Solutions/day-00-input.txt b/AdventOfCode.Solutions/day-00-input.txt index d4d4441..b60e466 100644 --- a/AdventOfCode.Solutions/day-00-input.txt +++ b/AdventOfCode.Solutions/day-00-input.txt @@ -1,28 +1,10 @@ -47|53 -97|13 -97|61 -97|47 -75|29 -61|13 -75|53 -29|13 -97|29 -53|29 -61|53 -97|53 -61|29 -47|13 -75|47 -97|75 -47|61 -75|61 -47|29 -75|13 -53|13 - -75,47,61,53,29 -97,61,53,29,13 -75,29,13 -75,97,47,61,53 -61,13,29 -97,13,75,29,47 \ No newline at end of file +....#..... +.........# +.......... +..#....... +.......#.. +.......... +.#..^..... +........#. +#......... +......#... \ No newline at end of file