completed day four part 1
This commit is contained in:
@@ -24,6 +24,10 @@
|
|||||||
<Content Include="Input\DayThree.txt">
|
<Content Include="Input\DayThree.txt">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
|
<None Remove="Input\DayFour.txt" />
|
||||||
|
<Content Include="Input\DayFour.txt">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -1,9 +1,44 @@
|
|||||||
namespace AdventOfCode2025;
|
using AdventOfCode2025.Utils;
|
||||||
|
|
||||||
|
namespace AdventOfCode2025;
|
||||||
|
|
||||||
public class PrintingDepartment : IAdventSolution
|
public class PrintingDepartment : IAdventSolution
|
||||||
{
|
{
|
||||||
|
private readonly HashSet<Coordinate> _existingRolls = new();
|
||||||
public AdventSolution Solve(string input)
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -11,5 +11,5 @@ AdventSolver<GiftShop>.Solve(dayTwoInput, 2, "Gift Shop");
|
|||||||
var dayThreeInput = await File.ReadAllTextAsync("./Input/DayThree.txt");
|
var dayThreeInput = await File.ReadAllTextAsync("./Input/DayThree.txt");
|
||||||
AdventSolver<Lobby>.Solve(dayThreeInput, 3, "Lobby");
|
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");
|
AdventSolver<PrintingDepartment>.Solve(dayFourInput, 4, "Printing Department");
|
||||||
Reference in New Issue
Block a user