From 629467f3769d1760caed9128aed9c7d8328f66b6 Mon Sep 17 00:00:00 2001 From: Sebastian Lindemeier Date: Mon, 8 Dec 2025 09:35:26 +0100 Subject: [PATCH] Refactor Day08 to improve readability with LINQ --- AoC_2025/Day08.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/AoC_2025/Day08.cs b/AoC_2025/Day08.cs index 22f3284..374c91f 100644 --- a/AoC_2025/Day08.cs +++ b/AoC_2025/Day08.cs @@ -123,10 +123,14 @@ public class Day08 return combinations; } - private IEnumerable<(TValue a, TValue b)> Combinations(IEnumerable values) + private IEnumerable<(TValue a, TValue b)> Combinations(IEnumerable values) where TValue:IComparable { - var enumerated = values.ToArray(); - return enumerated - .SelectMany((valueA, ix) => enumerated.Skip(ix + 1).Select(valueB => (valueA, valueB))); + 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; } } \ No newline at end of file