Skip to content
This repository was archived by the owner on Dec 28, 2024. It is now read-only.

Commit 2114235

Browse files
committed
Add solution day 12 part 2
1 parent 279074e commit 2114235

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,5 @@ automatically rebuilt and redeployed ever time the `common` module or their own
5656
| 09 | | 22 | |
5757
| 10 | ⭐ ⭐ | 23 | |
5858
| 11 | ⭐ ⭐ | 24 | |
59-
| 12 | | 25 | |
59+
| 12 | | 25 | |
6060
| 13 | | | |

solutions/day12/main.go

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type plot struct {
1515
}
1616

1717
func main() {
18-
common.Setup(12, part1, nil)
18+
common.Setup(12, part1, part2)
1919
}
2020

2121
func part1(
@@ -99,6 +99,7 @@ func countField(
9999
return 0, 0, 0
100100
}
101101
visited[c.String()] = true
102+
label := plots[c.Y][c.X].Label
102103

103104
area := 1
104105
perimeter := 0
@@ -107,13 +108,22 @@ func countField(
107108
e := c.East()
108109
s := c.South()
109110
w := c.West()
111+
ne := c.NorthEast()
112+
nw := c.NorthWest()
113+
se := c.SouthEast()
114+
sw := c.SouthWest()
110115

111-
label := plots[c.Y][c.X].Label
112116
nSame := isSameField(plots, label, n)
113117
eSame := isSameField(plots, label, e)
114118
sSame := isSameField(plots, label, s)
115119
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)
117127

118128
if nSame {
119129
a, p, c := countField(plots, n, visited)
@@ -171,19 +181,35 @@ func countCorners(
171181
eSame bool,
172182
sSame bool,
173183
wSame bool,
184+
neSame bool,
185+
nwSame bool,
186+
seSame bool,
187+
swSame bool,
174188
) int {
175189
sum := 0
176190
if !nSame && !eSame {
177191
sum++
192+
} else if nSame && eSame && !neSame {
193+
sum++
178194
}
195+
179196
if !nSame && !wSame {
180197
sum++
198+
} else if nSame && wSame && !nwSame {
199+
sum++
181200
}
201+
182202
if !sSame && !eSame {
183203
sum++
204+
} else if sSame && eSame && !seSame {
205+
sum++
184206
}
207+
185208
if !sSame && !wSame {
186209
sum++
210+
} else if sSame && wSame && !swSame {
211+
sum++
187212
}
213+
188214
return sum
189215
}

0 commit comments

Comments
 (0)