File tree Expand file tree Collapse file tree 2 files changed +84
-0
lines changed Expand file tree Collapse file tree 2 files changed +84
-0
lines changed Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "fmt"
5
+ "strconv"
6
+ "strings"
7
+
8
+ "github.com/robbkidd/aoc2022/tools"
9
+ )
10
+
11
+ func main () {
12
+ input := parseInput (tools .Read ("day04" ))
13
+ fmt .Printf ("Part 1: %v\n " , p1 (input ))
14
+ fmt .Printf ("Part 2: %v\n " , p2 (input ))
15
+ }
16
+
17
+ func p1 (lines []string ) int {
18
+ var fullyCovered int
19
+ for _ , line := range lines {
20
+ pair := strings .Split (line , "," )
21
+ left := strings .Split (pair [0 ], "-" )
22
+ right := strings .Split (pair [1 ], "-" )
23
+ leftStart , _ := strconv .Atoi (left [0 ])
24
+ leftStop , _ := strconv .Atoi (left [1 ])
25
+ rightStart , _ := strconv .Atoi (right [0 ])
26
+ rightStop , _ := strconv .Atoi (right [1 ])
27
+
28
+ if leftStart >= rightStart && leftStop <= rightStop {
29
+ fullyCovered ++
30
+ continue
31
+ }
32
+
33
+ if leftStart <= rightStart && leftStop >= rightStop {
34
+ fullyCovered ++
35
+ continue
36
+ }
37
+ }
38
+ return fullyCovered
39
+ }
40
+
41
+ func p2 (input []string ) int {
42
+ return 0
43
+ }
44
+
45
+ type Pair struct {
46
+ left Assignment
47
+ right Assignment
48
+ }
49
+ type Assignment struct {
50
+ start int
51
+ stop int
52
+ }
53
+
54
+ func parseInput (input string ) []string {
55
+ return tools .Lines (input )
56
+ }
Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "testing"
5
+
6
+ "github.com/stretchr/testify/assert"
7
+ )
8
+
9
+ func TestExamplePart1 (t * testing.T ) {
10
+ assert .Equal (t ,
11
+ 2 ,
12
+ p1 (parseInput (example )))
13
+ }
14
+
15
+ // func TestExamplePart2(t *testing.T) {
16
+ // assert.Equal(t,
17
+ // 'heyo',
18
+ // p2(parseInput(example)))
19
+ // }
20
+
21
+ const (
22
+ example = `2-4,6-8
23
+ 2-3,4-5
24
+ 5-7,7-9
25
+ 2-8,3-7
26
+ 6-6,4-6
27
+ 2-6,4-8`
28
+ )
You can’t perform that action at this time.
0 commit comments