From 35eb89c494e04cdbd43fd9945c38a24bf52f8810 Mon Sep 17 00:00:00 2001 From: Boxfriend Date: Thu, 4 Dec 2025 00:38:21 -0500 Subject: [PATCH] completed day 4 --- AdventOfCode2025/PrintingDepartment.cs | 27 +++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/AdventOfCode2025/PrintingDepartment.cs b/AdventOfCode2025/PrintingDepartment.cs index d77beed..1c10263 100644 --- a/AdventOfCode2025/PrintingDepartment.cs +++ b/AdventOfCode2025/PrintingDepartment.cs @@ -16,14 +16,27 @@ public class PrintingDepartment : IAdventSolution _existingRolls.Add(new Coordinate(j, i)); } } - - var accessible = 0; - foreach (var c in _existingRolls) + var initialCount = _existingRolls.Count; + var accessible = -1; + var firstAccessible = -1; + var toRemove = new HashSet(); + while(accessible != 0 && _existingRolls.Count > 0) { - if(IsAccessible(c)) accessible++; - } - - return new AdventSolution(accessible.ToString(), null); + accessible = 0; + foreach (var c in _existingRolls) + { + if (!IsAccessible(c)) continue; + accessible++; + toRemove.Add(c); + } + + if (firstAccessible == -1) firstAccessible = accessible; + + _existingRolls.RemoveWhere(x => toRemove.Contains(x)); + toRemove.Clear(); + } + + return new AdventSolution(firstAccessible.ToString(), (initialCount - _existingRolls.Count).ToString()); } private readonly Coordinate[] _directions =