From e64fd1f5c52f9023129c5c1c816490921653fc6b Mon Sep 17 00:00:00 2001 From: Dimitrios Kaltzidis Date: Tue, 3 Dec 2024 08:47:08 +0200 Subject: [PATCH] Day 3 code clean up --- Day3/Program.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Day3/Program.cs b/Day3/Program.cs index 27c704e..d7b904b 100644 --- a/Day3/Program.cs +++ b/Day3/Program.cs @@ -1,7 +1,6 @@ using System.Text.RegularExpressions; var memory = File.ReadAllText("input.txt"); - var result = ParseCorruptedMemory(memory); var resultPart2 = ParseCorruptedMemoryPart2(memory); Console.WriteLine($"Part1: {result}\nPart2: {resultPart2}"); @@ -35,8 +34,8 @@ int ParseCorruptedMemoryPart2(string corruptedMemory) var dontMatches = Regex.Matches(corruptedMemory, dontPattern); var allMatches = mulMatches - .Concat(doMatches.Cast()) - .Concat(dontMatches.Cast()) + .Concat(doMatches) + .Concat(dontMatches) .OrderBy(m => m.Index) .ToList(); @@ -54,9 +53,8 @@ int ParseCorruptedMemoryPart2(string corruptedMemory) } else if (Regex.IsMatch(match.Value, mulPattern) && mulEnabled) { - var mulMatch = (Match)match; - var x = int.Parse(mulMatch.Groups[1].Value); - var y = int.Parse(mulMatch.Groups[2].Value); + var x = int.Parse(match.Groups[1].Value); + var y = int.Parse(match.Groups[2].Value); results.Add(x * y); } }