generated from mazharenko/aoc-agent-template-multipleyears
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e787f02
commit 508a2de
Showing
3 changed files
with
57 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,48 @@ | ||
using System.Text.RegularExpressions; | ||
using mazharenko.AoCAgent.Generator; | ||
|
||
namespace aoc.Year2024.Day03; | ||
|
||
internal partial class Day03 | ||
{ | ||
internal partial class Part1 | ||
{ | ||
public string Solve(string input) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
internal partial class Part1 | ||
{ | ||
private readonly Example example = new( | ||
"xmul(2,4)%&mul[3,7]!@^do_not_mul(5,5)+mul(32,64]then(mul(11,8)mul(8,5))", | ||
161 | ||
); | ||
|
||
public long Solve(string input) | ||
{ | ||
var regex = new Regex(@"mul\((?<operand1>\d+),(?<operand2>\d+)\)"); | ||
return regex.Matches(input).Sum(m => | ||
int.Parse(m.Groups["operand1"].Value) | ||
* int.Parse(m.Groups["operand2"].Value) | ||
); | ||
} | ||
} | ||
|
||
internal partial class Part2 | ||
{ | ||
private readonly Example example = new( | ||
"xmul(2,4)&mul[3,7]!^don't()_mul(5,5)+mul(32,64](mul(11,8)undo()?mul(8,5))", | ||
48 | ||
); | ||
|
||
public long Solve(string input) | ||
{ | ||
var regex = new Regex(@"do\(\)|don't\(\)|mul\((?<operand1>\d+),(?<operand2>\d+)\)"); | ||
|
||
internal partial class Part2 | ||
{ | ||
public string Solve(string input) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
return regex.Matches(input) | ||
.Aggregate((enabled: true, sum: 0), | ||
(x, match) => match.Value switch | ||
{ | ||
"do()" => (true, x.sum), | ||
"don't()" => (false, x.sum), | ||
_ => x.enabled | ||
? (true, x.sum + int.Parse(match.Groups["operand1"].Value) * int.Parse(match.Groups["operand2"].Value)) | ||
: x | ||
}).sum; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.