-
Notifications
You must be signed in to change notification settings - Fork 3
/
util.go
54 lines (47 loc) · 1.02 KB
/
util.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
54
package aoc
import (
"strconv"
"strings"
)
func CommaNums(input string) []int64 {
ss := strings.Split(input, ",")
ns := make([]int64, len(ss))
for i, s := range ss {
ns[i], _ = strconv.ParseInt(s, 10, 64)
}
return ns
}
func CommaLinesNums(input string) [][]int64 {
lines := strings.Split(input, "\n")
ns := make([][]int64, len(lines))
for i, line := range lines {
ns[i] = CommaNums(line)
}
return ns
}
func SepLinesStrs(input string, sep string) [][]string {
lines := strings.Split(input, "\n")
ss := make([][]string, len(lines))
for i, line := range lines {
ss[i] = strings.Split(line, sep)
}
return ss
}
func CommaLinesStrs(input string) [][]string {
return SepLinesStrs(input, ",")
}
func Digits(input string) []int {
ds := make([]int, len(input))
for i := 0; i < len(input); i++ {
ds[i] = int(input[i] - '0')
}
return ds
}
func DigitLines(input string) [][]int {
lines := strings.Split(input, "\n")
ds := make([][]int, len(lines))
for i, line := range lines {
ds[i] = Digits(line)
}
return ds
}