Skip to content

Commit ae6d2b7

Browse files
committed
2023/01 with regex
1 parent a2c7cd7 commit ae6d2b7

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

2023/Day01/Solution.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@ public object PartOne(string input) =>
1212
public object PartTwo(string input) =>
1313
Solve(input, @"\d|one|two|three|four|five|six|seven|eight|nine");
1414

15-
int Solve(string input, string rx) =>
16-
input.Split("\n").Select(line => GetNumber(line, rx)).Sum();
17-
18-
int GetNumber(string line, string rx) {
19-
var first = Regex.Match(line, rx);
20-
var last = Regex.Match(line, rx, RegexOptions.RightToLeft);
21-
return ParseMatch(first.Value) * 10 + ParseMatch(last.Value);
22-
}
15+
int Solve(string input, string rx) => (
16+
from line in input.Split("\n")
17+
let first = Regex.Match(line, rx)
18+
let last = Regex.Match(line, rx, RegexOptions.RightToLeft)
19+
select ParseMatch(first.Value) * 10 + ParseMatch(last.Value)
20+
).Sum();
2321

2422
int ParseMatch(string st) => st switch {
2523
"" => 0, // no match

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy