File tree Expand file tree Collapse file tree 1 file changed +14
-14
lines changed Expand file tree Collapse file tree 1 file changed +14
-14
lines changed Original file line number Diff line number Diff line change @@ -18,20 +18,20 @@ int Solve(string input, string rx) =>
18
18
int GetNumber ( string line , string rx ) {
19
19
var first = Regex . Match ( line , rx ) ;
20
20
var last = Regex . Match ( line , rx , RegexOptions . RightToLeft ) ;
21
-
22
- return ParseMatch ( first ) * 10 + ParseMatch ( last ) ;
21
+ return ParseMatch ( first . Value ) * 10 + ParseMatch ( last . Value ) ;
23
22
}
24
23
25
- int ParseMatch ( Match m ) =>
26
- ! m . Success ? 0 :
27
- m . Groups [ 0 ] . Value == "one" ? 1 :
28
- m . Groups [ 0 ] . Value == "two" ? 2 :
29
- m . Groups [ 0 ] . Value == "three" ? 3 :
30
- m . Groups [ 0 ] . Value == "four" ? 4 :
31
- m . Groups [ 0 ] . Value == "five" ? 5 :
32
- m . Groups [ 0 ] . Value == "six" ? 6 :
33
- m . Groups [ 0 ] . Value == "seven" ? 7 :
34
- m . Groups [ 0 ] . Value == "eight" ? 8 :
35
- m . Groups [ 0 ] . Value == "nine" ? 9 :
36
- int . Parse ( m . Groups [ 0 ] . Value ) ;
24
+ int ParseMatch ( string st ) => st switch {
25
+ "" => 0 , // no match
26
+ "one" => 1 ,
27
+ "two" => 2 ,
28
+ "three" => 3 ,
29
+ "four" => 4 ,
30
+ "five" => 5 ,
31
+ "six" => 6 ,
32
+ "seven" => 7 ,
33
+ "eight" => 8 ,
34
+ "nine" => 9 ,
35
+ var d => int . Parse ( d )
36
+ } ;
37
37
}
You can’t perform that action at this time.
0 commit comments