From d878ab186e173f817efa97ddb9cdb888dee7cd33 Mon Sep 17 00:00:00 2001 From: Sebastian Lindemeier Date: Tue, 16 Dec 2025 08:00:03 +0100 Subject: [PATCH] Refactor `Permutations` in `EnumerableExtensions` by extracting `RotateIndices` method to simplify and reuse index rotation logic --- .../EnumerableExtensions.cs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/AdventOfCode.Extensions/EnumerableExtensions.cs b/AdventOfCode.Extensions/EnumerableExtensions.cs index 6df27a8..20c5efd 100644 --- a/AdventOfCode.Extensions/EnumerableExtensions.cs +++ b/AdventOfCode.Extensions/EnumerableExtensions.cs @@ -117,12 +117,7 @@ public static class EnumerableExtensions cycles[i] -= 1; if (cycles[i] == 0) { - var tmp = indices[i]; - for (var j = i; j < indices.Length - 1; j++) - { - indices[j] = indices[j + 1]; - } - indices[^1] = tmp; + RotateIndices(indices, i); cycles[i] = poolLength - i; } else @@ -135,6 +130,18 @@ public static class EnumerableExtensions } } } + + yield break; + + static void RotateIndices(int[] indices, int from) + { + var tmp = indices[from]; + for (var j = from; j < indices.Length - 1; j++) + { + indices[j] = indices[j + 1]; + } + indices[^1] = tmp; + } } private static TValue[] GetCombination(int[] innerIndices, TValue[] innerPool) =>