Refactor Day08 to improve readability with LINQ

This commit is contained in:
Sebastian Lindemeier 2025-12-08 09:35:26 +01:00
parent 7a02ba6b0e
commit 629467f376
1 changed files with 8 additions and 4 deletions

View File

@ -123,10 +123,14 @@ public class Day08
return combinations; return combinations;
} }
private IEnumerable<(TValue a, TValue b)> Combinations<TValue>(IEnumerable<TValue> values) private IEnumerable<(TValue a, TValue b)> Combinations<TValue>(IEnumerable<TValue> values) where TValue:IComparable
{ {
var enumerated = values.ToArray(); var enumeratedValues = values.Index().ToArray();
return enumerated var pairs =
.SelectMany((valueA, ix) => enumerated.Skip(ix + 1).Select(valueB => (valueA, valueB))); from a in enumeratedValues
from b in enumeratedValues
where a.Index < b.Index
select (a.Item, b.Item);
return pairs;
} }
} }