-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
39 lines (29 loc) · 668 Bytes
/
main.go
File metadata and controls
39 lines (29 loc) · 668 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import (
"regexp"
"github.com/danvolchek/AdventOfCode/lib"
)
var numberRegexp = regexp.MustCompile(`-?[0-9]+`)
func solve(input string) int {
matches := numberRegexp.FindAllString(input, -1)
sum := 0
for _, match := range matches {
sum += lib.Atoi(match)
}
return sum
}
func main() {
solver := lib.Solver[string, int]{
ParseF: lib.AsIs,
SolveF: solve,
}
solver.Expect(`[1,2,3]`, 6)
solver.Expect(`{"a":2,"b":4}`, 6)
solver.Expect(`[[[3]]]`, 3)
solver.Expect(`{"a":{"b":4},"c":-1}`, 3)
solver.Expect(`{"a":[-1,1]}`, 0)
solver.Expect(`[-1,{"a":1}]`, 0)
solver.Expect(`[]`, 0)
solver.Expect(`{}`, 0)
solver.Verify(119433)
}