From 3d60b3d1524bcbe65f4d5bd27a7918e24cce63db Mon Sep 17 00:00:00 2001 From: Paul Woitaschek Date: Thu, 12 Dec 2024 23:08:15 +0100 Subject: [PATCH] Remove the region class --- 2024/src/main/kotlin/aoc/year2024/Day12.kt | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/2024/src/main/kotlin/aoc/year2024/Day12.kt b/2024/src/main/kotlin/aoc/year2024/Day12.kt index b2cc3e9..f27aafe 100644 --- a/2024/src/main/kotlin/aoc/year2024/Day12.kt +++ b/2024/src/main/kotlin/aoc/year2024/Day12.kt @@ -17,13 +17,12 @@ object Day12 : Puzzle(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): List { - val regions = mutableListOf() + private fun clusterByRegions(garden: Map): List> { + val regions = mutableListOf>() val visited = mutableSetOf() garden.keys.forEach { start -> if (start !in visited) { @@ -40,7 +39,7 @@ object Day12 : Puzzle(12) { } } visit(start) - regions += Region(groupChar, group) + regions += group visited.addAll(group) } } @@ -65,6 +64,4 @@ object Day12 : Puzzle(12) { } } } - - private data class Region(val char: Char, val points: Set) }