This repository was archived by the owner on Dec 28, 2024. It is now read-only.
File tree 2 files changed +54
-2
lines changed
2 files changed +54
-2
lines changed Original file line number Diff line number Diff line change @@ -54,7 +54,7 @@ automatically rebuilt and redeployed ever time the `common` module or their own
54
54
| 07 | ⭐ ⭐ | 20 | |
55
55
| 08 | ⭐ ⭐ | 21 | |
56
56
| 09 | | 22 | |
57
- | 10 | ⭐ | 23 | |
57
+ | 10 | ⭐ ⭐ | 23 | |
58
58
| 11 | | 24 | |
59
59
| 12 | | 25 | |
60
60
| 13 | | | |
Original file line number Diff line number Diff line change 8
8
)
9
9
10
10
func main () {
11
- common .Setup (10 , part1 , nil )
11
+ common .Setup (10 , part1 , part2 )
12
12
}
13
13
14
14
func part1 (
@@ -34,6 +34,27 @@ func part1(
34
34
return fmt .Sprintf ("Number of trails: %d" , out )
35
35
}
36
36
37
+ func part2 (
38
+ input string ,
39
+ ) string {
40
+ topo := parseTopographicMap (input )
41
+
42
+ out := 0
43
+ for y := 0 ; y < len (topo ); y ++ {
44
+ row := topo [y ]
45
+ for x := 0 ; x < len (row ); x ++ {
46
+ value := topo [y ][x ]
47
+ if value != 0 {
48
+ continue
49
+ }
50
+
51
+ out += countDistinctTrails (topo , util.Coordinate {X : x , Y : y }, 0 )
52
+ }
53
+ }
54
+
55
+ return fmt .Sprintf ("Number of distinct trails: %d" , out )
56
+ }
57
+
37
58
func parseTopographicMap (
38
59
input string ,
39
60
) [][]int {
@@ -80,3 +101,34 @@ func buildMapForPart1(
80
101
}
81
102
}
82
103
}
104
+
105
+ func countDistinctTrails (
106
+ topographicMap [][]int ,
107
+ position util.Coordinate ,
108
+ value int ,
109
+ ) int {
110
+ if value == 9 {
111
+ return 1
112
+ }
113
+
114
+ cs := []util.Coordinate {
115
+ position .North (),
116
+ position .East (),
117
+ position .South (),
118
+ position .West (),
119
+ }
120
+
121
+ out := 0
122
+ for _ , c := range cs {
123
+ if ! util .In2DArray (c , topographicMap ) {
124
+ continue
125
+ }
126
+
127
+ cValue := topographicMap [c.Y ][c.X ]
128
+ if cValue == value + 1 {
129
+ out += countDistinctTrails (topographicMap , c , cValue )
130
+ }
131
+ }
132
+
133
+ return out
134
+ }
You can’t perform that action at this time.
0 commit comments