From a4d072ae1709216a1916154f75f78ccb0198eb61 Mon Sep 17 00:00:00 2001 From: TiagoRG Date: Thu, 8 Jun 2023 13:59:21 +0100 Subject: [PATCH] Added Utils namespace --- Utils/Extensions.cs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Utils/Extensions.cs diff --git a/Utils/Extensions.cs b/Utils/Extensions.cs new file mode 100644 index 0000000..222cc07 --- /dev/null +++ b/Utils/Extensions.cs @@ -0,0 +1,32 @@ +namespace AdventOfCode.Utils; + +public static class Extensions +{ + /// + /// Returns a slice of the given list + /// + /// The list you pretend to slice + /// The first index of the slice + /// The index after the last index of the slice + /// + public static List Sublist(this List list, int startIndex, int endIndex) + { + List result = new List(); + for (int i = startIndex; i < endIndex; i++) + result.Add(list[i]); + return result; + } + + /// + /// Returns a column of a give matrix list + /// + /// 2 dimensions list + /// Column index + /// + public static List GetColumn(this List> list, int column) + { + List result = new List(); + foreach (List row in list) result.AddRange(row.Where((t, i) => i == column)); + return result; + } +} \ No newline at end of file