diff --git a/README.md b/README.md index eb7242c..f411d18 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ _My solutions to the 2024 edition of [Advent of Code](https://adventofcode.com/2 | **[09](https://adventofcode.com/2024/day/9)** | [solution](src/main/scala/adventofcode/solutions/Day09.scala) | | **[10](https://adventofcode.com/2024/day/10)** | [solution](src/main/scala/adventofcode/solutions/Day10.scala) | | **[11](https://adventofcode.com/2024/day/11)** | [solution](src/main/scala/adventofcode/solutions/Day11.scala) | -| **[12](https://adventofcode.com/2024/day/12)** | [](src/main/scala/adventofcode/solutions/Day12.scala) | +| **[12](https://adventofcode.com/2024/day/12)** | [solution](src/main/scala/adventofcode/solutions/Day12.scala) | | **[13](https://adventofcode.com/2024/day/13)** | [](src/main/scala/adventofcode/solutions/Day13.scala) | | **[14](https://adventofcode.com/2024/day/14)** | [](src/main/scala/adventofcode/solutions/Day14.scala) | | **[15](https://adventofcode.com/2024/day/15)** | [](src/main/scala/adventofcode/solutions/Day15.scala) | diff --git a/input/12.txt b/input/12.txt new file mode 100644 index 0000000..33cef8a --- /dev/null +++ b/input/12.txt @@ -0,0 +1,140 @@ +MMMMMMMMQMMZZRRXRRRRUUUUUUUUUUUUUUUUEEDEEEEEEEEEEEEEEEEEUUDDDDLLLLLLLLLLLLLJJJJJSSJJCCCCCCCCEEEEEEEEESSSSSSSSSSSSSSWWWWWWWWMMRRRRRRRRRIIIIII +MMMMMMMMMMMMZRRXRRRRUUUUUUUUUUUUUUUUEEEEEEEEEEKKKKKKEEEEUUUUDDDDLLLLLLLLLLLJJJJJJJJJJJCCCCCCEEEEEEEEESBSSSSSSSSSSSSWWWWWWWWMMMRRRRRRRRRIIIII +MMMMMMMMMMMZZRRRRRRRUUUUUUXUXUUUUUUUEEEEEEEEEEEKKKKKKKKGUUUUDDLLLLLLLULLULLJJJJJJJJJJJCCCCEEEEEEEEEESSBBBBSSSSSSSSSWWWWWWPWMMMRRRRRRRRRIIIII +MMMMMMMMMMNRRRERRRRRUUUU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ZZZZZZZZ +BBBBBBBBBBBRRRRJAAAAAAAAAAASQQQQQQQQQQQQQTTTLTLLLLTTLLLHHHHHHHHHDDDDHHRRRRRRRROOOORRRWWFFFHHHHICCCCCCCCCVRRRRRJJRRRRVVVVVVVTTVVTVIIIZZZZZZZZ +TTBBBBBBBBBRRRRRRLALLLAAAAGQQQQQQQQQQQQQTTTTTTTTTTTTTTTTHHHHHHHHHDHHHHARRJJRRROOOOORRRFFHHHHHHHHCCCCVVVVVRRRRRRRRRRRRVVVVVVVTVVVVVVVVVVZZZZZ +TBBBBBBBBBRRRRRRRLLLLLAAAAGQQQQQQQQQQQQQTTTTTTTTTTTTTTTHHHHHHHHQHAAAHHAARRRRRRRROORRRRFFFHHHHHHHCCCVVVVVRRRRRRRRRRRRVVVVVVVVVVVVVVVVVVVZZZZZ +TBBBBBBBBBBRRRRRRLLLLLLAAAGGQQQQQQQQQQQQTTTTTTTTTTTTTTTTTHHHHHHHAAAAAAAARAARAARRROFRRFFFFHHHHHHHCWCVVVVVRRRRRRRRRRRRRRVVVVVVVVVVVVVVFVVVVAAA +TTTTBBBBBBBRZRRLLLLLLLLAGGGGGGQQQQQQQQQQTTTTTTTTTTTTTTTTTHHHHPHHAAAAAAAAAAAAAAAARFFFFFFFFFHLHHHHWWCVVVVVRRRRRRRRRRERRRVVVVVVVVVVVVVVVVVVVAAA diff --git a/output/12-1.txt b/output/12-1.txt new file mode 100644 index 0000000..f8c5c26 --- /dev/null +++ b/output/12-1.txt @@ -0,0 +1 @@ +1465112 \ No newline at end of file diff --git a/output/12-2.txt b/output/12-2.txt new file mode 100644 index 0000000..3f475ac --- /dev/null +++ b/output/12-2.txt @@ -0,0 +1 @@ +893790 \ No newline at end of file diff --git a/src/main/scala/adventofcode/solutions/Day12.scala b/src/main/scala/adventofcode/solutions/Day12.scala new file mode 100644 index 0000000..8e29d34 --- /dev/null +++ b/src/main/scala/adventofcode/solutions/Day12.scala @@ -0,0 +1,67 @@ +package adventofcode.solutions + +import adventofcode.Definitions.* + +@main def Day12 = Day(12) { (input, part) => + + case class Vec(i: Int, j: Int): + infix def +(that: Vec): Vec = Vec(i + that.i, j + that.j) + infix def -(that: Vec): Vec = Vec(i - that.i, j - that.j) + infix def rotateCW: Vec = Vec(-j, i) + + val grid = input.toLines + + val adjacent = + for + i <- -1 to 1 + j <- -1 to 1 + if i.abs + j.abs == 1 + yield Vec(i, j) + + def inBounds(vec: Vec): Boolean = grid.indices.contains(vec.i) && grid(vec.i).indices.contains(vec.j) + + def bfsAll[T](nodes: Seq[T], adjacency: T => Set[T]): Set[Set[T]] = + def bfs(current: Set[T], visited: Set[T], excluded: Set[T]): Set[T] = + if current.nonEmpty then + val nextVisited = visited ++ current + val nextCurrent = current.flatMap(adjacency).diff(nextVisited).diff(excluded) + bfs(nextCurrent, nextVisited, excluded) + else + visited + val (result, _) = nodes.foldLeft((Set.empty[Set[T]], Set.empty[T])) { case ((regions, visited), node) => + if !visited.contains(node) then + val sideRegion = bfs(Set(node), Set.empty, visited) + (regions + sideRegion, visited ++ sideRegion) + else + (regions, visited + node) + } + result + + def area(region: Set[Vec]): Int = region.size + + def perimeter(region: Set[Vec]): Int = + region.toSeq.flatMap(p => adjacent.map(p + _)).count(!region.contains(_)) + + def sides(region: Set[Vec]): Int = + val allSides = region.toSeq.flatMap(p => adjacent.map(p + _).filter(!region.contains(_)).map(p -> _)) + val sidesGraph = allSides.map { side => + val (a, b) = side + side -> Set((a - b).rotateCW, (b - a).rotateCW).map(v => (a + v, b + v)) + }.toMap + bfsAll(allSides, sidesGraph.withDefaultValue(Set.empty)).size + + val regions = bfsAll( + grid.indices.flatMap(i => grid(i).indices.map(j => Vec(i, j))), + p => { + val region = grid(p.i)(p.j) + adjacent.map(p + _).filter(inBounds).filter(p => grid(p.i)(p.j) == region).toSet + } + ) + + def cost(f: Set[Vec] => Int): Int = regions.toSeq.map(r => area(r) * f(r)).sum + + part(1) = cost(perimeter) + + part(2) = cost(sides) + +}