Day 3 code clean up
This commit is contained in:
@@ -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<Match>())
|
||||
.Concat(dontMatches.Cast<Match>())
|
||||
.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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user