-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
41 lines (32 loc) · 745 Bytes
/
main.go
File metadata and controls
41 lines (32 loc) · 745 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
40
41
package main
import (
"regexp"
"strings"
"github.com/danvolchek/AdventOfCode/lib"
)
func decode(line string) string {
line = line[1 : len(line)-1]
line = strings.ReplaceAll(line, `\\`, `\`)
line = strings.ReplaceAll(line, `\"`, `"`)
line = regexp.MustCompile(`\\x[0-9a-f][0-9a-f]`).ReplaceAllString(line, "f")
return line
}
func solve(lines []string) int {
total := 0
for _, line := range lines {
total += len(line) - len(decode(line))
}
return total
}
func main() {
solver := lib.Solver[[]string, int]{
ParseF: lib.ParseLine(lib.AsIs),
SolveF: solve,
}
solver.Expect(`""`, 2)
solver.Expect(`"abc"`, 2)
solver.Expect(`"aaa\"aaa"`, 3)
solver.Expect(`"\x27"`, 5)
solver.Expect(`"\x27"`, 5)
solver.Verify(1350)
}