Skip to content

Commit 34fd37c

Browse files
committed
2022 day 4
1 parent 63750d6 commit 34fd37c

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

2022/go/day4/day4.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package main
33
import (
44
"fmt"
55
"os"
6-
"strconv"
76
"strings"
87
)
98

@@ -40,16 +39,7 @@ func (s1 sections) overlap(s2 sections) bool {
4039
}
4140

4241
func parsePair(line string) (sections, sections) {
43-
ranges := strings.Split(line, ",")
44-
return parseSection(ranges[0]), parseSection(ranges[1])
45-
}
46-
47-
func parseSection(r string) sections {
48-
ends := strings.Split(r, "-")
49-
return sections{start: atoi(ends[0]), end: atoi(ends[1])}
50-
}
51-
52-
func atoi(a string) int {
53-
i, _ := strconv.Atoi(a)
54-
return i
42+
var s1, s2 sections
43+
fmt.Sscanf(line, "%d-%d,%d-%d", &s1.start, &s1.end, &s2.start, &s2.end)
44+
return s1, s2
5545
}

0 commit comments

Comments
 (0)