|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.IO; |
| 4 | +using System.Runtime; |
| 5 | +using System.Security.Cryptography.X509Certificates; |
| 6 | +using System.Text.RegularExpressions; |
| 7 | + |
| 8 | +namespace adventofcode.Year2024.Day03; |
| 9 | + |
| 10 | +public class Solution : BaseSolution, ISolver |
| 11 | +{ |
| 12 | + public void SolvePart1() |
| 13 | + { |
| 14 | + //var inputFilePath = GetInputFilePath("test"); |
| 15 | + var inputFilePath = GetInputFilePath(); |
| 16 | + |
| 17 | + string[] lines = File.ReadAllLines(inputFilePath); |
| 18 | + |
| 19 | + string regexpattern = @"mul\(\d{1,3},\d{1,3}\)"; |
| 20 | + |
| 21 | + List<string> allmatches = new(); |
| 22 | + |
| 23 | + long totalSum = 0; |
| 24 | + foreach (var line in lines) |
| 25 | + { |
| 26 | + var matches = Regex.Matches(line, regexpattern); |
| 27 | + |
| 28 | + foreach(Match match in matches) |
| 29 | + { |
| 30 | + allmatches.Add(match.Value); |
| 31 | + |
| 32 | + string item = match.ToString().Replace("mul(", "").Replace(")", ""); |
| 33 | + |
| 34 | + long x = long.Parse(item.Split(',')[0]); |
| 35 | + long y = long.Parse(item.Split(',')[1]); |
| 36 | + |
| 37 | + totalSum += x * y; |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + Console.WriteLine($"allmatches.count = {allmatches.Count}"); |
| 42 | + Console.WriteLine($"total sum is: {totalSum}"); |
| 43 | + |
| 44 | + } |
| 45 | + |
| 46 | + public void SolvePart2() |
| 47 | + { |
| 48 | + throw new NotImplementedException(); |
| 49 | + } |
| 50 | +} |
0 commit comments