Skip to content

Commit

Permalink
Remove the region class
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulWoitaschek committed Dec 12, 2024
1 parent c9cd779 commit 3d60b3d
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions 2024/src/main/kotlin/aoc/year2024/Day12.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ object Day12 : Puzzle<Int, Int>(12) {
): Int {
val garden = parse(input)
return clusterByRegions(garden).sumOf {
val pointsInRegion = it.points
perimeter(pointsInRegion) * pointsInRegion.size
perimeter(it) * it.size
}
}

private fun clusterByRegions(garden: Map<Point, Char>): List<Region> {
val regions = mutableListOf<Region>()
private fun clusterByRegions(garden: Map<Point, Char>): List<Set<Point>> {
val regions = mutableListOf<Set<Point>>()
val visited = mutableSetOf<Point>()
garden.keys.forEach { start ->
if (start !in visited) {
Expand All @@ -40,7 +39,7 @@ object Day12 : Puzzle<Int, Int>(12) {
}
}
visit(start)
regions += Region(groupChar, group)
regions += group
visited.addAll(group)
}
}
Expand All @@ -65,6 +64,4 @@ object Day12 : Puzzle<Int, Int>(12) {
}
}
}

private data class Region(val char: Char, val points: Set<Point>)
}

0 comments on commit 3d60b3d

Please sign in to comment.