-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution.go
46 lines (42 loc) · 816 Bytes
/
solution.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
package main
import (
"fmt"
"os"
"regexp"
"strconv"
"strings"
)
func main() {
input, err := os.ReadFile("./input.txt")
if err != nil {
panic(err)
}
lines := strings.Split(string(input), "\n")
count := 0
for _, line := range lines {
if line == "" {
continue
}
sections := regexp.MustCompile(",|-").Split(line, -1);
var sec [4]int;
for i, section := range sections {
value, err := strconv.Atoi(section);
if err != nil {
panic(err)
}
sec[i] = value
}
if os.Getenv("part") == "part2" {
if sec[1] >= sec[2] && sec[0] <= sec[3] {
count++
}
} else {
if sec[0] >= sec[2] && sec[1] <= sec[3] {
count++
} else if sec[2] >= sec[0] && sec[3] <= sec[1] {
count++
}
}
}
fmt.Println(count)
}