File tree 4 files changed +2096
-0
lines changed
4 files changed +2096
-0
lines changed Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "fmt"
5
+ "io/ioutil"
6
+ "strconv"
7
+ "strings"
8
+ )
9
+
10
+ type Period struct {
11
+ start int
12
+ end int
13
+ }
14
+
15
+ func NewPeriod (start , end int ) Period {
16
+ return Period {start : start , end : end }
17
+ }
18
+
19
+ func (p Period ) Contains (other Period ) bool {
20
+ return p .start >= other .start && p .end <= other .end
21
+ }
22
+
23
+ func main () {
24
+ bytesRead , _ := ioutil .ReadFile ("input.txt" )
25
+ fileContent := string (bytesRead )
26
+ lines := strings .Split (fileContent , "\n " )
27
+
28
+ var result int
29
+
30
+ for _ , line := range lines {
31
+ elves := strings .Split (line , "," )
32
+ var periods []Period
33
+ for _ , elf := range elves {
34
+ points := strings .Split (elf , "-" )
35
+ start , _ := strconv .Atoi (points [0 ])
36
+ end , _ := strconv .Atoi (points [1 ])
37
+ periods = append (periods , NewPeriod (start , end ))
38
+ }
39
+
40
+ if periods [0 ].Contains (periods [1 ]) || periods [1 ].Contains (periods [0 ]) {
41
+ result += 1
42
+ }
43
+ }
44
+
45
+ fmt .Println (result )
46
+ }
You can’t perform that action at this time.
0 commit comments