Refactor Day08 to reorder methods and simplify circuit connection logic
This commit is contained in:
parent
a3ac176602
commit
9d8a611f76
|
|
@ -33,11 +33,6 @@ public class Day08
|
||||||
.Aggregate((acc, next) => acc * next);
|
.Aggregate((acc, next) => acc * next);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<List<Coordinate>> CreateCircuits(Coordinate[] jBoxes)
|
|
||||||
{
|
|
||||||
return jBoxes.Select(p => new List<Coordinate> { p }).ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public long SolvePart2(string pathToPuzzleInput)
|
public long SolvePart2(string pathToPuzzleInput)
|
||||||
{
|
{
|
||||||
var jBoxes = ParsePuzzleInput(pathToPuzzleInput);
|
var jBoxes = ParsePuzzleInput(pathToPuzzleInput);
|
||||||
|
|
@ -47,15 +42,17 @@ public class Day08
|
||||||
return lastConnected.a.x * lastConnected.b.x;
|
return lastConnected.a.x * lastConnected.b.x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<List<Coordinate>> CreateCircuits(Coordinate[] jBoxes)
|
||||||
|
{
|
||||||
|
return jBoxes.Select(p => new List<Coordinate> { p }).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
private List<List<Coordinate>> CombineCircuits(List<List<Coordinate>> circuits,
|
private List<List<Coordinate>> CombineCircuits(List<List<Coordinate>> circuits,
|
||||||
(Coordinate boxA, Coordinate boxB)[] jBoxPairs, int amountToConnect)
|
(Coordinate boxA, Coordinate boxB)[] jBoxPairs, int amountToConnect)
|
||||||
{
|
{
|
||||||
for (var i = 0; i < amountToConnect; i++)
|
circuits = jBoxPairs
|
||||||
{
|
.Take(amountToConnect)
|
||||||
var nextToConnect = jBoxPairs[i];
|
.Aggregate(circuits, (acc, next) => ConnectJBoxes(next.boxA, next.boxB, acc));
|
||||||
circuits = ConnectJBoxes(nextToConnect.boxA, nextToConnect.boxB, circuits);
|
|
||||||
}
|
|
||||||
|
|
||||||
return circuits;
|
return circuits;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue