Initial Days
This commit is contained in:
25
Day3/Program.cs
Normal file
25
Day3/Program.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System.Text.RegularExpressions;
|
||||
// string input = "xmul(2,4)&mul[3,7]!^don't()_mul(5,5)+mul(32,64](mul(11,8)undo()?mul(8,5))";
|
||||
string input = File.ReadAllText("input.txt").ReplaceLineEndings("");
|
||||
int total = 0;
|
||||
|
||||
Regex valid = new Regex("mul\\((?<x>[0-9]+),(?<y>[0-9]+)\\)");
|
||||
Regex dontandDo = new Regex("(don\\'t\\(\\).*?do\\(\\))");
|
||||
|
||||
input = dontandDo.Replace(input, "");
|
||||
|
||||
List<(int x, int y)> multiplies = new();
|
||||
|
||||
foreach (Match match in valid.Matches(input))
|
||||
{
|
||||
string x = match.Groups["x"].Value;
|
||||
string y = match.Groups["y"].Value;
|
||||
multiplies.Add((int.Parse(x), int.Parse(y)));
|
||||
}
|
||||
|
||||
foreach ((int x, int y) in multiplies)
|
||||
{
|
||||
total += x * y;
|
||||
}
|
||||
|
||||
Console.WriteLine(total);
|
||||
Reference in New Issue
Block a user