Extract Combinations method to AdventOfCode.Extensions and refactor usages to improve modularity and reduce duplication
This commit is contained in:
+3
-12
@@ -4,6 +4,7 @@ using System.Data.Common;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using AdvenOfCode.Contracts;
|
||||
using AdventOfCode.Extensions;
|
||||
using Coordinate = (long x, long y, long z);
|
||||
|
||||
namespace AoC_2025;
|
||||
@@ -92,21 +93,11 @@ public class Day08 : IPuzzleSolver<long>
|
||||
|
||||
private IEnumerable<(Coordinate boxA, Coordinate boxB)> GetAllCombinationsSortedByDistance(IEnumerable<Coordinate> jBoxes)
|
||||
{
|
||||
var combinations = Combinations(jBoxes)
|
||||
var combinations = jBoxes.Combinations(2)
|
||||
.Select(x => (a: x[0], b: x[1]))
|
||||
.OrderBy(x => GetDistance(x.a, x.b));
|
||||
return combinations;
|
||||
}
|
||||
|
||||
private IEnumerable<(TValue a, TValue b)> Combinations<TValue>(IEnumerable<TValue> values)
|
||||
{
|
||||
var enumeratedValues = values.Index().ToArray();
|
||||
var pairs =
|
||||
from a in enumeratedValues
|
||||
from b in enumeratedValues
|
||||
where a.Index < b.Index
|
||||
select (a.Item, b.Item);
|
||||
return pairs;
|
||||
}
|
||||
|
||||
private long MultiplyLargestCircuitLength(List<HashSet<Coordinate>> circuits, int amountMultiply)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user