From 9d8a611f7672903bd5ba8df6e822e6b63e5175ee Mon Sep 17 00:00:00 2001 From: Sebastian Lindemeier Date: Mon, 8 Dec 2025 11:35:09 +0100 Subject: [PATCH] Refactor Day08 to reorder methods and simplify circuit connection logic --- AoC_2025/Day08.cs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/AoC_2025/Day08.cs b/AoC_2025/Day08.cs index da3b0ab..e7c35d9 100644 --- a/AoC_2025/Day08.cs +++ b/AoC_2025/Day08.cs @@ -33,11 +33,6 @@ public class Day08 .Aggregate((acc, next) => acc * next); } - private List> CreateCircuits(Coordinate[] jBoxes) - { - return jBoxes.Select(p => new List { p }).ToList(); - } - public long SolvePart2(string pathToPuzzleInput) { var jBoxes = ParsePuzzleInput(pathToPuzzleInput); @@ -47,15 +42,17 @@ public class Day08 return lastConnected.a.x * lastConnected.b.x; } + private List> CreateCircuits(Coordinate[] jBoxes) + { + return jBoxes.Select(p => new List { p }).ToList(); + } + private List> CombineCircuits(List> circuits, (Coordinate boxA, Coordinate boxB)[] jBoxPairs, int amountToConnect) { - for (var i = 0; i < amountToConnect; i++) - { - var nextToConnect = jBoxPairs[i]; - circuits = ConnectJBoxes(nextToConnect.boxA, nextToConnect.boxB, circuits); - } - + circuits = jBoxPairs + .Take(amountToConnect) + .Aggregate(circuits, (acc, next) => ConnectJBoxes(next.boxA, next.boxB, acc)); return circuits; }