File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -30,8 +30,30 @@ func solvePart1(input string) int {
30
30
return totalDistance
31
31
}
32
32
33
+ func solvePart2 (input string ) int {
34
+ left , right , err := inputs .ExtractIntPairs (input )
35
+ if err != nil {
36
+ panic (err )
37
+ }
38
+
39
+ rightCount := make (map [int ]int )
40
+ similarityScore := 0
41
+
42
+ for _ , rnum := range right {
43
+ rightCount [rnum ]++
44
+ }
45
+
46
+ for _ , lnum := range left {
47
+ similarityScore += lnum * rightCount [lnum ]
48
+ }
49
+
50
+ return similarityScore
51
+ }
52
+
33
53
func main () {
34
54
part1Solution := solvePart1 (input )
55
+ part2Solution := solvePart2 (input )
35
56
36
57
fmt .Println ("Day 01 Part 1 solution:" , part1Solution )
58
+ fmt .Println ("Day 01 Part 2 solution:" , part2Solution )
37
59
}
Original file line number Diff line number Diff line change @@ -9,12 +9,21 @@ import (
9
9
var test1 string
10
10
11
11
func TestSolution (t * testing.T ) {
12
- t .Run ("Day 01 part 1 test 1 " , func (t * testing.T ) {
12
+ t .Run ("Day 01 part 1" , func (t * testing.T ) {
13
13
want := 11
14
14
got := solvePart1 (test1 )
15
15
16
16
if got != want {
17
17
t .Errorf ("Incorrect solution, got %d want %d" , got , want )
18
18
}
19
19
})
20
+
21
+ t .Run ("Day 01 part 2" , func (t * testing.T ) {
22
+ want := 31
23
+ got := solvePart2 (test1 )
24
+
25
+ if got != want {
26
+ t .Errorf ("Incorrect solution, got %d want %d" , got , want )
27
+ }
28
+ })
20
29
}
You can’t perform that action at this time.
0 commit comments