completed day four part 1

This commit is contained in:
2025-12-04 00:31:51 -05:00
parent 1487a1cd27
commit b175cf9812
3 changed files with 42 additions and 3 deletions

View File

@@ -24,6 +24,10 @@
<Content Include="Input\DayThree.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Remove="Input\DayFour.txt" />
<Content Include="Input\DayFour.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>

View File

@@ -1,9 +1,44 @@
namespace AdventOfCode2025;
using AdventOfCode2025.Utils;
namespace AdventOfCode2025;
public class PrintingDepartment : IAdventSolution
{
private readonly HashSet<Coordinate> _existingRolls = new();
public AdventSolution Solve(string input)
{
throw new NotImplementedException();
var map = input.SplitLines();
for (var i = 0; i < map.Length; i++)
{
for (var j = 0; j < map[i].Length; j++)
{
if(map[i][j] != '.')
_existingRolls.Add(new Coordinate(j, i));
}
}
var accessible = 0;
foreach (var c in _existingRolls)
{
if(IsAccessible(c)) accessible++;
}
return new AdventSolution(accessible.ToString(), null);
}
private readonly Coordinate[] _directions =
[
new(-1, -1), new( 0, -1), new( 1, -1),
new(-1, 0), new( 1, 0),
new(-1, 1), new( 0, 1), new( 1, 1)
];
private bool IsAccessible(Coordinate position)
{
var neighbors = 0;
foreach (var dir in _directions)
{
if(_existingRolls.Contains(position + dir)) neighbors++;
}
return neighbors < 4;
}
}

View File

@@ -11,5 +11,5 @@ AdventSolver<GiftShop>.Solve(dayTwoInput, 2, "Gift Shop");
var dayThreeInput = await File.ReadAllTextAsync("./Input/DayThree.txt");
AdventSolver<Lobby>.Solve(dayThreeInput, 3, "Lobby");
var dayFourInput = await File.ReadAllTextAsync("./Input/Test.txt");
var dayFourInput = await File.ReadAllTextAsync("./Input/DayFour.txt");
AdventSolver<PrintingDepartment>.Solve(dayFourInput, 4, "Printing Department");