@@ -3,6 +3,7 @@ package main
3
3
import (
4
4
"fmt"
5
5
"github.com/terminalnode/adventofcode2024/common"
6
+ "github.com/terminalnode/adventofcode2024/common/util"
6
7
"regexp"
7
8
"strconv"
8
9
)
@@ -14,9 +15,9 @@ func main() {
14
15
}
15
16
16
17
func part1 (
17
- input string ,
18
- ) string {
19
- finds := r .FindAllSubmatch ([]byte (input ), - 1 )
18
+ input util. AocInput ,
19
+ ) (util. AocSolution , util. AocError ) {
20
+ finds := r .FindAllSubmatch ([]byte (input . Input ), - 1 )
20
21
sum := 0
21
22
for _ , match := range finds {
22
23
verb := string (match [1 ])
@@ -26,17 +27,17 @@ func part1(
26
27
27
28
multiplied , err := mul (string (match [3 ]), string (match [4 ]))
28
29
if err != nil {
29
- return fmt .Sprintf ("Failed to parse multiplication of %q:\n %v\n " , match , err )
30
+ return util . NewAocError ( fmt .Sprintf ("Failed to parse multiplication of %q:\n %v\n " , match , err ), util . ParsingError )
30
31
}
31
32
sum += multiplied
32
33
}
33
- return fmt . Sprintf ("Result: %d" , sum )
34
+ return util . FormatAocSolution ("Result: %d" , sum )
34
35
}
35
36
36
37
func part2 (
37
- input string ,
38
- ) string {
39
- finds := r .FindAllSubmatch ([]byte (input ), - 1 )
38
+ input util. AocInput ,
39
+ ) (util. AocSolution , util. AocError ) {
40
+ finds := r .FindAllSubmatch ([]byte (input . Input ), - 1 )
40
41
sum := 0
41
42
42
43
enabled := true
@@ -47,7 +48,7 @@ func part2(
47
48
if enabled {
48
49
multiplied , err := mul (string (match [3 ]), string (match [4 ]))
49
50
if err != nil {
50
- return fmt .Sprintf ("Failed to parse multiplication of %q:\n %v\n " , match , err )
51
+ return util . NewAocError ( fmt .Sprintf ("Failed to parse multiplication of %q:\n %v\n " , match , err ), util . ParsingError )
51
52
}
52
53
sum += multiplied
53
54
}
@@ -58,7 +59,7 @@ func part2(
58
59
}
59
60
}
60
61
61
- return fmt . Sprintf ("Result: %d" , sum )
62
+ return util . FormatAocSolution ("Result: %d" , sum )
62
63
}
63
64
64
65
func mul (sub1 string , sub2 string ) (int , error ) {
0 commit comments