Skip to content

Commit

Permalink
day 1 part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaKateryna committed Dec 1, 2023
1 parent d1e34e2 commit cf61f28
Show file tree
Hide file tree
Showing 2 changed files with 1,017 additions and 3 deletions.
19 changes: 17 additions & 2 deletions AdventOfCode/Day01.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace AdventOfCode;
using System.Text.RegularExpressions;

namespace AdventOfCode;

public class Day01 : BaseDay
{
Expand All @@ -9,7 +11,20 @@ public Day01()
_input = File.ReadAllText(InputFilePath);
}

public override ValueTask<string> Solve_1() => new($"Solution to {ClassPrefix} {CalculateIndex()}, part 1");
public override ValueTask<string> Solve_1()
{
string[] lines = _input.Split(Environment.NewLine);
long sum = 0;

foreach (string item in lines)
{
MatchCollection matches = Regex.Matches(item, "[0-9]");
int calibrationValue = int.Parse(matches.First().Value + matches.Last().Value);
sum += calibrationValue;
}

return new(sum.ToString());
}

public override ValueTask<string> Solve_2() => new($"Solution to {ClassPrefix} {CalculateIndex()}, part 2");
}
Loading

0 comments on commit cf61f28

Please sign in to comment.