-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
53 lines (40 loc) · 868 Bytes
/
main.go
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
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"strconv"
"github.com/danvolchek/AdventOfCode/lib"
)
func expand(input []byte) []byte {
var result []byte
for i := 0; i < len(input); {
j := i + 1
for j < len(input) && input[i] == input[j] {
j++
}
result = append(result, []byte(strconv.Itoa(j-i))...)
result = append(result, input[i])
i = j
}
return result
}
func solve(input []byte) int {
for i := 0; i < 50; i++ {
input = expand(input)
}
return len(input)
}
func main() {
expandTest := lib.Solver[[]byte, string]{
ParseF: lib.ParseBytes,
SolveF: lib.ToString(expand),
}
expandTest.Expect("1", "11")
expandTest.Expect("11", "21")
expandTest.Expect("21", "1211")
expandTest.Expect("1211", "111221")
expandTest.Expect("111221", "312211")
solver := lib.Solver[[]byte, int]{
ParseF: lib.ParseBytes,
SolveF: solve,
}
solver.Verify(5103798)
}