Skip to content

Commit

Permalink
Update to Smab.Helpers v1.7.29
Browse files Browse the repository at this point in the history
  • Loading branch information
smabuk committed Dec 18, 2024
1 parent b0ac960 commit b5bc7df
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageVersion Include="Spectre.Console" Version="0.49.1" />
<PackageVersion Include="xunit" Version="2.9.2" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.0.0" />
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
<PackageVersion Include="Shouldly" Version="4.2.1" />
<PackageVersion Include="AngleSharp" Version="1.1.2" />
<PackageVersion Include="Smab.Helpers" Version="1.7.27" />
<PackageVersion Include="Smab.Helpers" Version="1.7.29" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion Solutions/2024/Day12.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private static IEnumerable<Edge> FindPlotEdges(this List<Point> 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)));
}
Expand Down
12 changes: 6 additions & 6 deletions Solutions/2024/Day15.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);

Expand All @@ -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
{
Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
Expand All @@ -199,7 +199,7 @@ private static (bool Yes, List<WideBox> 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);

Expand Down
12 changes: 8 additions & 4 deletions Solutions/2024/Day16.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -48,7 +52,7 @@ public static int Part2(string[] _)
List<ReindeerPosition> 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<ReindeerPosition>)> FindAllPaths(this char[,] maze, ReindeerPosition start, Point end)
Expand All @@ -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)
Expand Down Expand Up @@ -114,7 +118,7 @@ private static (int, List<ReindeerPosition>) 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;
Expand Down
2 changes: 1 addition & 1 deletion Solutions/2024/Day18.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static List<Point> 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;
Expand Down
5 changes: 4 additions & 1 deletion Tests/2016/AdventOfCode.Tests.2016.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
<PackageReference Include="coverlet.collector" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" />
<PackageReference Include="xunit.runner.visualstudio">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 4 additions & 1 deletion Tests/2017/AdventOfCode.Tests.2017.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
<PackageReference Include="coverlet.collector" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" />
<PackageReference Include="xunit.runner.visualstudio">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 4 additions & 1 deletion Tests/2024/AdventOfCode.Tests.2024.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
<PackageReference Include="coverlet.collector" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" />
<PackageReference Include="xunit.runner.visualstudio">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit b5bc7df

Please sign in to comment.