From b5bc7dfded3d91445a7444e4c07fc566a6f97df5 Mon Sep 17 00:00:00 2001 From: smabuk <2011834+smabuk@users.noreply.github.com> Date: Wed, 18 Dec 2024 16:06:48 +0000 Subject: [PATCH] Update to Smab.Helpers v1.7.29 --- Directory.Packages.props | 4 ++-- Solutions/2024/Day12.cs | 2 +- Solutions/2024/Day15.cs | 12 ++++++------ Solutions/2024/Day16.cs | 12 ++++++++---- Solutions/2024/Day18.cs | 2 +- Tests/2016/AdventOfCode.Tests.2016.csproj | 5 ++++- Tests/2017/AdventOfCode.Tests.2017.csproj | 5 ++++- Tests/2024/AdventOfCode.Tests.2024.csproj | 5 ++++- 8 files changed, 30 insertions(+), 17 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 0de7f97a..5953336f 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -9,10 +9,10 @@ - + - + \ No newline at end of file diff --git a/Solutions/2024/Day12.cs b/Solutions/2024/Day12.cs index ce3cd971..fc4551bd 100644 --- a/Solutions/2024/Day12.cs +++ b/Solutions/2024/Day12.cs @@ -99,7 +99,7 @@ private static IEnumerable FindPlotEdges(this List plots) return plots .SelectMany(plot => Directions.NSEW - .Select(direction => (Direction: direction, Next: plot + direction.Delta())) + .Select(direction => (Direction: direction, Next: plot.Translate(direction))) .Where(x => plotSet.DoesNotContain(x.Next)) .Select(x => new Edge(Plot: x.Next, Direction: x.Direction))); } diff --git a/Solutions/2024/Day15.cs b/Solutions/2024/Day15.cs index 2a4f0f89..35072e2e 100644 --- a/Solutions/2024/Day15.cs +++ b/Solutions/2024/Day15.cs @@ -48,7 +48,7 @@ public static int Part1(string[] _) private static bool TryMovePart1(this Thing thing, Direction direction, char[,] map, out Thing newThing) { - newThing = thing with { Location = thing.Location + direction.Delta() }; + newThing = thing with { Location = thing.Location.Translate(direction) }; char value = newThing.GetTheValue(map); if (value is BOX) { @@ -90,7 +90,7 @@ public static int Part2(string[] _) private static bool TryMoveRobot(this Robot robot, Direction direction, char[,] map, out Thing newRobot) { - newRobot = robot with { Location = robot.Location + direction.Delta() }; + newRobot = robot with { Location = robot.Location.Translate(direction) }; char value = newRobot.GetTheValue(map); @@ -115,7 +115,7 @@ private static bool TryMoveRobot(this Robot robot, Direction direction, char[,] private static bool TryMoveBox(this WideBox box, Direction direction, char[,] map) { - WideBox newBox = box with { Location = box.Location + direction.Delta() }; + WideBox newBox = box with { Location = box.Location.Translate(direction) }; return direction switch { @@ -174,7 +174,7 @@ private static bool TryMoveBoxVertically(this WideBox newBox, WideBox box, Direc }; foreach (WideBox boxToMove in boxes) { - newBox = box with { Location = boxToMove.Location + direction.Delta() }; + newBox = box with { Location = boxToMove.Location.Translate(direction) }; map.UpdateMap(boxToMove, EMPTY, EMPTY); map.UpdateMap(newBox, BOX_LEFT, BOX_RIGHT); } @@ -184,7 +184,7 @@ private static bool TryMoveBoxVertically(this WideBox newBox, WideBox box, Direc } if (value1 is EMPTY && value2 is EMPTY) { - newBox = box with { Location = box.Location + direction.Delta() }; + newBox = box with { Location = box.Location.Translate(direction) }; map.UpdateMap(box, EMPTY, EMPTY); map.UpdateMap(newBox, BOX_LEFT, BOX_RIGHT); return true; @@ -199,7 +199,7 @@ private static (bool Yes, List WideBoxes) CanIMove(this WideBox? box, D return (true, []); } - WideBox newBox = box with { Location = box.Location + direction.Delta() }; + WideBox newBox = box with { Location = box.Location.Translate(direction) }; char value1 = newBox.L.GetTheValue(map); char value2 = newBox.R.GetTheValue(map); diff --git a/Solutions/2024/Day16.cs b/Solutions/2024/Day16.cs index 688b04ad..f94b4d25 100644 --- a/Solutions/2024/Day16.cs +++ b/Solutions/2024/Day16.cs @@ -37,8 +37,12 @@ public static int Part1(string[] _) return lowestScore; } - public static int Part2(string[] _) + public static string Part2(string[] _) { + if (_maze.ColsCount() > 20) { + return NO_SOLUTION_MESSAGE; + } + ReindeerPosition reindeerPosition = new(_maze.ForEachCell().Single(c => c.Value is START).Index, East); Point end = _maze.ForEachCell().Single(c => c.Value is END).Index; @@ -48,7 +52,7 @@ public static int Part2(string[] _) List tiles = [..routes.Where(r => r.Score == lowestScore).SelectMany(p => p.Route)]; _maze.VisualiseMaze($"Tiles:", tiles.Select(r => r with { Direction = None })); - return tiles.Select(p => p.Position).Distinct().Count(); + return tiles.Select(p => p.Position).Distinct().Count().ToString(); } private static IEnumerable<(int, List)> FindAllPaths(this char[,] maze, ReindeerPosition start, Point end) @@ -70,7 +74,7 @@ public static int Part2(string[] _) _ = visited.Add(reindeerPosition); foreach (Direction direction in Directions.NESW) { - ReindeerPosition newPosition = reindeerPosition with { Position = reindeerPosition.Position + direction.Delta(), Direction = direction}; + ReindeerPosition newPosition = reindeerPosition with { Position = reindeerPosition.Position.Translate(direction), Direction = direction}; if (maze[newPosition.Position.X, newPosition.Position.Y] is not WALL //&& path.DoesNotContain(newPosition) @@ -114,7 +118,7 @@ private static (int, List) FindShortestPath(this char[,] maze, } foreach (Direction direction in Directions.NESW) { - Point newPosition = position + direction.Delta(); + Point newPosition = position.Translate(direction); if (maze.TryGetValue(newPosition, out char value) && value is not WALL) { int turnCost = (prevDir != direction) ? TURN_COST : 0; diff --git a/Solutions/2024/Day18.cs b/Solutions/2024/Day18.cs index 4a557d40..6f5f6e28 100644 --- a/Solutions/2024/Day18.cs +++ b/Solutions/2024/Day18.cs @@ -68,7 +68,7 @@ public static List FindShortestPath(Point start, Point goal, IEnumerable< } foreach (Direction direction in Directions.NSEW) { - Point adjacent = current + direction.Delta(); + Point adjacent = current.Translate(direction); if (adjacent.IsOutOfBounds(size) || corruptions.Contains(adjacent)) { continue; diff --git a/Tests/2016/AdventOfCode.Tests.2016.csproj b/Tests/2016/AdventOfCode.Tests.2016.csproj index c3db1ea4..7fd313b7 100644 --- a/Tests/2016/AdventOfCode.Tests.2016.csproj +++ b/Tests/2016/AdventOfCode.Tests.2016.csproj @@ -12,7 +12,10 @@ - + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/Tests/2017/AdventOfCode.Tests.2017.csproj b/Tests/2017/AdventOfCode.Tests.2017.csproj index 36567334..60224654 100644 --- a/Tests/2017/AdventOfCode.Tests.2017.csproj +++ b/Tests/2017/AdventOfCode.Tests.2017.csproj @@ -12,7 +12,10 @@ - + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/Tests/2024/AdventOfCode.Tests.2024.csproj b/Tests/2024/AdventOfCode.Tests.2024.csproj index 4c2aaf37..94fc1b46 100644 --- a/Tests/2024/AdventOfCode.Tests.2024.csproj +++ b/Tests/2024/AdventOfCode.Tests.2024.csproj @@ -12,7 +12,10 @@ - + + all + runtime; build; native; contentfiles; analyzers; buildtransitive +