@@ -15,7 +15,7 @@ type plot struct {
15
15
}
16
16
17
17
func main () {
18
- common .Setup (12 , part1 , nil )
18
+ common .Setup (12 , part1 , part2 )
19
19
}
20
20
21
21
func part1 (
@@ -99,6 +99,7 @@ func countField(
99
99
return 0 , 0 , 0
100
100
}
101
101
visited [c .String ()] = true
102
+ label := plots [c.Y ][c.X ].Label
102
103
103
104
area := 1
104
105
perimeter := 0
@@ -107,13 +108,22 @@ func countField(
107
108
e := c .East ()
108
109
s := c .South ()
109
110
w := c .West ()
111
+ ne := c .NorthEast ()
112
+ nw := c .NorthWest ()
113
+ se := c .SouthEast ()
114
+ sw := c .SouthWest ()
110
115
111
- label := plots [c.Y ][c.X ].Label
112
116
nSame := isSameField (plots , label , n )
113
117
eSame := isSameField (plots , label , e )
114
118
sSame := isSameField (plots , label , s )
115
119
wSame := isSameField (plots , label , w )
116
- corners := countCorners (nSame , eSame , sSame , wSame )
120
+ neSame := isSameField (plots , label , ne )
121
+ nwSame := isSameField (plots , label , nw )
122
+ seSame := isSameField (plots , label , se )
123
+ swSame := isSameField (plots , label , sw )
124
+
125
+ // Haters gonna hate
126
+ corners := countCorners (nSame , eSame , sSame , wSame , neSame , nwSame , seSame , swSame )
117
127
118
128
if nSame {
119
129
a , p , c := countField (plots , n , visited )
@@ -171,19 +181,35 @@ func countCorners(
171
181
eSame bool ,
172
182
sSame bool ,
173
183
wSame bool ,
184
+ neSame bool ,
185
+ nwSame bool ,
186
+ seSame bool ,
187
+ swSame bool ,
174
188
) int {
175
189
sum := 0
176
190
if ! nSame && ! eSame {
177
191
sum ++
192
+ } else if nSame && eSame && ! neSame {
193
+ sum ++
178
194
}
195
+
179
196
if ! nSame && ! wSame {
180
197
sum ++
198
+ } else if nSame && wSame && ! nwSame {
199
+ sum ++
181
200
}
201
+
182
202
if ! sSame && ! eSame {
183
203
sum ++
204
+ } else if sSame && eSame && ! seSame {
205
+ sum ++
184
206
}
207
+
185
208
if ! sSame && ! wSame {
186
209
sum ++
210
+ } else if sSame && wSame && ! swSame {
211
+ sum ++
187
212
}
213
+
188
214
return sum
189
215
}
0 commit comments