diff --git a/README.md b/README.md index abb7f25..4caa2a1 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ | 2021 | ★ | ★ | ★ | ★ | ★ | ★ | ★ | ★ | ★ | ★ | ★ | | ★ | ★ | | | | | | | | | | | | 26 | | 2022 | ★ | ★ | ★ | ★ | ★ | ★ | ★ | ★ | ★ | ★ | ★ | ★ | ★ | | | | | | | | ☆ | | | | ☆ | 28 | | 2023 | ★ | ★ | ★ | ★ | ☆ | ★ | ☆ | | | | | | | | | | | | | | | | | | | 12 | -| 2024 | ★ | ★ | ★ | ★ | ★ | ★ | ★ | ★ | ★ | ★ | ★ | ★ | ★ | ★ | | ☆ | ★ | ★ | ★ | ★ | | ★ | | | | 39 | +| 2024 | ★ | ★ | ★ | ★ | ★ | ★ | ★ | ★ | ★ | ★ | ★ | ★ | ★ | ★ | | ☆ | ★ | ★ | ★ | ★ | | ★ | | | ☆ | 40 | ## 🛷 How to run @@ -184,6 +184,7 @@ e.g. `HandyHaversacks`)* | | 19 | [Linen Layout](https://adventofcode.com/2024/day/19) | [[Code](src/main/kotlin/adventofcode/year2024/Day19LinenLayout.kt)] [[Test](src/test/kotlin/adventofcode/year2024/Day19LinenLayoutSpec.kt)] | `267` | `796449099271652` | | | 20 | [Race Condition](https://adventofcode.com/2024/day/20) | [[Code](src/main/kotlin/adventofcode/year2024/Day20RaceCondition.kt)] [[Test](src/test/kotlin/adventofcode/year2024/Day20RaceConditionSpec.kt)] | `1426` | `1000697` | | | 22 | [Monkey Market](https://adventofcode.com/2024/day/22) | [[Code](src/main/kotlin/adventofcode/year2024/Day22MonkeyMarket.kt)] [[Test](src/test/kotlin/adventofcode/year2024/Day22MonkeyMarketSpec.kt)] | `20332089158` | `2191` | +| | 25 | [Code Chronicle](https://adventofcode.com/2024/day/25) | [[Code](src/main/kotlin/adventofcode/year2024/Day25CodeChronicle.kt)] [[Test](src/test/kotlin/adventofcode/year2024/Day25CodeChronicleSpec.kt)] | `3608` | | ## 🕯️ Useful commands diff --git a/src/main/kotlin/adventofcode/common/spatial/Grid2d.kt b/src/main/kotlin/adventofcode/common/spatial/Grid2d.kt index 6fd962c..37fbb8a 100644 --- a/src/main/kotlin/adventofcode/common/spatial/Grid2d.kt +++ b/src/main/kotlin/adventofcode/common/spatial/Grid2d.kt @@ -1,7 +1,8 @@ package adventofcode.common.spatial data class Grid2d(val values: List>) { - val points = values.flatMapIndexed { y, row -> List(row.size) { x -> Point2d(x, y) } } + /** Set of points contained in this grid. */ + val points = values.flatMapIndexed { y, row -> List(row.size) { x -> Point2d(x, y) } }.toSet() /** `true` for a square grid, `false` otherwise. */ val isSquare: Boolean = values.all { row -> row.size == values.size } @@ -19,7 +20,19 @@ data class Grid2d(val values: List>) { override fun toString(): String = values.joinToString("\n") { row -> row.toString() } /** Returns the number of columns for a given row in the grid. */ - fun colsInRow(row: Int) = values[row].size + fun columnsInRow(row: Int) = values[row].size + + /** Returns the row of elements at the given row index. */ + fun rowAt(index: Int): List = values[index] + + /** Returns the column of elements at the given column index. */ + fun columnAt(index: Int): List = values.map { row -> row[index] } + + /** Syntactic sugar for nested `values` list. */ + fun rows(): List> = values + + /** Returns all the columns of the grid. */ + fun columns(): List> = rotate().values.map(List::reversed) /** Returns `true` if the grid contains `value`. */ operator fun contains(value: T): Boolean = values.flatten().contains(value) @@ -73,6 +86,7 @@ data class Grid2d(val values: List>) { } companion object { + /** Create a new `Grid2d` from a `String` where each point is a character of that string. */ operator fun invoke(values: String) = Grid2d(values.lines().map(String::toList)) } } diff --git a/src/main/kotlin/adventofcode/common/spatial/Point2d.kt b/src/main/kotlin/adventofcode/common/spatial/Point2d.kt index 73cfd7a..7a59207 100644 --- a/src/main/kotlin/adventofcode/common/spatial/Point2d.kt +++ b/src/main/kotlin/adventofcode/common/spatial/Point2d.kt @@ -6,13 +6,10 @@ data class Point2d( val x: Long, val y: Long, ) { + /** Alternative constructor to allow other Number types as coordinates, e.g. `Int`s. */ constructor(x: Number, y: Number) : this(x.toLong(), y.toLong()) - /** - * Pretty formatted String representation. - * - * (0, 1) - */ + /** Pretty formatted String representation: (0, 1) */ override fun toString(): String = "($x, $y)" /** Add two points together by adding their x and y coordinates. */ @@ -41,7 +38,7 @@ data class Point2d( .map { direction -> this + direction } .toSet() - /** Returns the manhattan distance between two points. */ + /** Returns the Manhattan distance between two points. */ infix fun distanceTo(other: Point2d): Long = (x - other.x).absoluteValue + (y - other.y).absoluteValue companion object { diff --git a/src/main/kotlin/adventofcode/year2024/Day04CeresSearch.kt b/src/main/kotlin/adventofcode/year2024/Day04CeresSearch.kt index 1b94918..7ec3c75 100644 --- a/src/main/kotlin/adventofcode/year2024/Day04CeresSearch.kt +++ b/src/main/kotlin/adventofcode/year2024/Day04CeresSearch.kt @@ -18,7 +18,7 @@ class Day04CeresSearch(customInput: PuzzleInput? = null) : Puzzle(customInput) { val length = xmas.length return (0 until rows).flatMap { row -> - (0 until colsInRow(row)).flatMap { col -> + (0 until columnsInRow(row)).flatMap { col -> val horizontal = (0 until length).map { y -> Point2d(row, col + y) }.filter { point -> point in this } val vertical = (0 until length).map { x -> Point2d(row + x, col) }.filter { point -> point in this } val rightDiagonal = (0 until length).map { d -> Point2d(row + d, col + d) }.filter { point -> point in this } @@ -37,7 +37,7 @@ class Day04CeresSearch(customInput: PuzzleInput? = null) : Puzzle(customInput) { val length = mas.length return (0..rows - length).flatMap { row -> - (0..colsInRow(row) - length).map { col -> + (0..columnsInRow(row) - length).map { col -> val topDiagonal = (0 until length).map { d -> Point2d(row + d, col + d) } val bottomDiagonal = (0 until length).map { d -> Point2d(row + length - 1 - d, col + d) } diff --git a/src/main/kotlin/adventofcode/year2024/Day25CodeChronicle.kt b/src/main/kotlin/adventofcode/year2024/Day25CodeChronicle.kt new file mode 100644 index 0000000..375b2df --- /dev/null +++ b/src/main/kotlin/adventofcode/year2024/Day25CodeChronicle.kt @@ -0,0 +1,35 @@ +package adventofcode.year2024 + +import adventofcode.Puzzle +import adventofcode.PuzzleInput +import adventofcode.common.cartesianProduct +import adventofcode.common.spatial.Grid2d + +class Day25CodeChronicle(customInput: PuzzleInput? = null) : Puzzle(customInput) { + private val schematics by lazy { input.split("\n\n").map { Grid2d(it) } } + private val locks by lazy { + schematics + .filter { schematic -> schematic.rowAt(0).all { it == FILLED } && schematic.rowAt(schematic.rows - 1).all { it == EMPTY } } + .map { schematic -> Grid2d(schematic.values.drop(1).dropLast(1)) } + .toSet() + } + private val keys by lazy { + schematics + .map { schematic -> Grid2d(schematic.values.drop(1).dropLast(1)) } + .minus(locks) + .toSet() + } + + override fun partOne() = + listOf(locks, keys) + .cartesianProduct() + .map { (lock, key) -> lock.toHeights().zip(key.toHeights()) { lockHeight, keyHeight -> lockHeight + keyHeight } } + .count { lockKeyPair -> lockKeyPair.all { height -> height <= 5 } } + + companion object { + private const val FILLED = '#' + private const val EMPTY = '.' + + private fun Grid2d.toHeights(): List = columns().map { column -> column.count { it == FILLED } } + } +} diff --git a/src/main/resources/inputs/year2024/day25.txt b/src/main/resources/inputs/year2024/day25.txt new file mode 100644 index 0000000..8438534 --- /dev/null +++ b/src/main/resources/inputs/year2024/day25.txt @@ -0,0 +1,3999 @@ +..... +..#.. +.##.. +.##.. +.##.. +####. +##### + +..... +...#. +...#. +#.##. +#.### +#.### +##### + +##### +.###. +.##.. +.#... +.#... +.#... +..... + +..... +...#. +..### +.#### +.#### +.#### +##### + +..... +.#... +.#... +##... +##..# +##.## +##### + +##### +.##.# +.##.# +.##.# +.#... +.#... +..... + +..... +..... +..... +.#..# +.##.# +.#### +##### + +##### +#.#.# +#...# +....# +..... +..... +..... + +##### +##.## +##.## +#..## +....# +..... +..... + +..... +..... +..... +..... +..... +.#.#. +##### + +..... +..#.. +#.#.. +#.#.. +#.##. +####. +##### + +..... +..... +...#. +..### +.#### +.#### +##### + +..... +..#.. +..#.. +.##.. +###.. +####. +##### + +##### +.##.# +..#.# +..... +..... +..... +..... + +..... +#..#. +#..#. +#..## +#..## +#.### +##### + +##### +##### +##### +.##.# +.##.# +..#.# +..... + +..... +.#.#. +####. +##### +##### +##### +##### + +##### +##.## +##.## +##..# +#...# +..... +..... + +..... +#..#. +#..#. +##.#. +##.#. +##.#. +##### + +##### +##.## +.#.## +.#.#. +...#. +...#. +..... + +##### +#.### +#.#.# +..#.# +..#.. +..#.. +..... + +##### +##### +##.## +.#..# +.#..# +....# +..... + +..... +#.... +#.... +#.#.. +#.#.# +#.### +##### + +##### +###.# +#.#.# +#.#.. +#.... +#.... +..... + +##### +##### +####. +####. +##.#. +.#.#. +..... + +##### +##### +.#### +.#### +.##.# +.#... +..... + +##### +##### +##.#. +##.#. +.#... +..... +..... + +##### +##### +#.#.# +#...# +..... +..... +..... + +##### +##### +#.### +#.##. +#..#. +#..#. +..... + +##### +.###. +..#.. +..... +..... +..... +..... + +..... +..... +.#... +.##.# +##### +##### +##### + +##### +####. +####. +.##.. +.#... +.#... +..... + +##### +###.# +###.# +##... +.#... +..... +..... + +##### +.#### +.#.## +.#..# +.#... +.#... +..... + +##### +.#.## +.#.## +.#.## +.#..# +..... +..... + +..... +..... +..#.# +..#.# +#.### +#.### +##### + +..... +..#.# +.##.# +.##.# +###.# +##### +##### + +..... +#.... +#.... +#.#.# +###.# +###.# +##### + +..... +..#.. +#.##. +#.##. +#.##. +##### +##### + +..... +#.... +#.#.. +#.##. +#.##. +#.### +##### + +..... +#.... +#.#.. +###.. +###.# +###.# +##### + +##### +##### +.#.## +.#.## +...## +....# +..... + +..... +....# +.#..# +.#..# +.##.# +.##.# +##### + +##### +##### +##### +#.##. +..##. +..#.. +..... + +##### +####. +###.. +#.#.. +..#.. +..#.. +..... + +##### +#.### +...## +...#. +...#. +...#. +..... + +##### +.#### +.#### +.#.## +....# +....# +..... + +##### +##.## +##.## +.#.## +.#..# +..... +..... + +..... +..... +.#... +.#... +.#.#. +.#.#. +##### + +##### +###.# +###.# +.##.# +.#... +.#... +..... + +##### +#.### +#.#.# +#.#.# +....# +....# +..... + +##### +###.# +.##.# +.#..# +..... +..... +..... + +..... +.#.#. +.#.#. +##.#. +##.#. +##### +##### + +..... +..... +.#..# +###.# +##### +##### +##### + +##### +##.## +##.## +#..## +....# +....# +..... + +..... +...#. +#.##. +####. +####. +####. +##### + +..... +..... +..#.. +..#.. +.##.. +.###. +##### + +##### +.###. +.###. +.###. +.##.. +..#.. +..... + +##### +##### +.#### +.##.# +..#.# +..#.# +..... + +##### +.###. +.#.#. +.#.#. +...#. +...#. +..... + +..... +..... +.#... +.##.# +###.# +##### +##### + +##### +##### +#.### +..#.# +..#.# +..#.. +..... + +##### +##### +#.### +#.### +#..#. +...#. +..... + +##### +.##.# +.##.# +.#..# +.#..# +.#... +..... + +..... +..... +.#..# +.#..# +.#.## +.#.## +##### + +##### +###.# +.#..# +.#..# +....# +....# +..... + +..... +..#.. +.##.. +###.# +###.# +###.# +##### + +..... +..... +#..#. +#.### +##### +##### +##### + +##### +####. +#.##. +#..#. +...#. +...#. +..... + +..... +....# +...## +#..## +#.### +#.### +##### + +##### +##### +##### +##.## +.#..# +....# +..... + +##### +##### +##.## +.#..# +.#..# +.#... +..... + +..... +...#. +...## +..### +..### +.#### +##### + +..... +#.... +#.... +#.#.. +###.. +####. +##### + +##### +##### +##### +.#### +.##.# +..#.. +..... + +##### +##### +.#### +.#.## +.#.#. +.#.#. +..... + +..... +..... +..#.. +.###. +.#### +.#### +##### + +##### +.#### +.#.## +...## +....# +..... +..... + +##### +##### +##### +#.### +#.#.# +#.#.# +..... + +..... +..... +..... +...#. +#..#. +##.#. +##### + +##### +#.#.# +#.#.. +#.#.. +..#.. +..#.. +..... + +..... +.#..# +.#..# +.#..# +##.## +##### +##### + +##### +##### +##### +##### +#.##. +#..#. +..... + +##### +##### +#.### +..##. +..##. +...#. +..... + +..... +..#.. +#.#.. +#.#.# +#.#.# +#.#.# +##### + +##### +###.# +.##.# +.##.. +.#... +..... +..... + +..... +.#... +.#..# +.##.# +.##.# +###.# +##### + +##### +###.# +###.. +###.. +##... +#.... +..... + +..... +..... +.#.#. +.#### +.#### +##### +##### + +##### +#.### +..### +..#.# +....# +....# +..... + +..... +..... +....# +.#.## +##.## +##### +##### + +..... +..... +....# +.#..# +.#..# +.##.# +##### + +##### +.##.# +.#..# +.#..# +.#..# +....# +..... + +##### +##.#. +#..#. +#..#. +#..#. +..... +..... + +..... +..... +..... +..#.. +#.##. +#.##. +##### + +..... +#..#. +#..#. +##.#. +##.## +##### +##### + +##### +##### +#.### +#.### +#..#. +#..#. +..... + +..... +...#. +..##. +..##. +.###. +.#### +##### + +##### +##.## +##.#. +.#.#. +..... +..... +..... + +..... +.#... +##.#. +##.#. +##.#. +##### +##### + +..... +.#... +.#... +.##.. +.##.# +##### +##### + +..... +..#.. +..#.. +.##.. +####. +####. +##### + +..... +.#... +.##.. +###.. +####. +##### +##### + +##### +####. +####. +#.##. +#.##. +#.#.. +..... + +..... +....# +#.#.# +#.#.# +#.#.# +#.#.# +##### + +##### +##### +##### +####. +.#.#. +...#. +..... + +##### +##### +####. +#.#.. +#.#.. +#.#.. +..... + +..... +..... +..... +#.#.# +###.# +###.# +##### + +..... +..#.. +..#.# +#.#.# +#.#.# +#.#.# +##### + +##### +##.## +#..## +...## +...## +....# +..... + +..... +#...# +##.## +##.## +##### +##### +##### + +..... +..... +.#.#. +.#.#. +##.## +##.## +##### + +##### +#.##. +#..#. +...#. +..... +..... +..... + +##### +####. +####. +####. +###.. +.#... +..... + +..... +..#.. +..#.. +..#.# +#.### +#.### +##### + +..... +#...# +##..# +##..# +##..# +##.## +##### + +..... +..#.# +#.#.# +#.#.# +###.# +###.# +##### + +##### +#.### +..#.# +....# +....# +..... +..... + +..... +..... +....# +#..## +#.### +#.### +##### + +##### +##### +###.# +#.#.# +#...# +#...# +..... + +..... +.#... +.#.#. +.#.#. +####. +##### +##### + +##### +##### +###.# +###.# +#.#.. +..#.. +..... + +##### +##### +##.#. +.#.#. +.#.#. +.#.#. +..... + +##### +#.### +#.### +..#.# +..#.# +....# +..... + +##### +.#### +..### +...## +...#. +..... +..... + +..... +..... +.#... +.#..# +.#..# +.##.# +##### + +##### +.###. +.###. +..##. +..##. +...#. +..... + +##### +#.### +#.#.# +..... +..... +..... +..... + +##### +#.#.# +#.#.# +#.#.. +#.#.. +..... +..... + +##### +##### +##.#. +#.... +#.... +#.... +..... + +..... +#.... +#..#. +#..#. +##.## +##.## +##### + +##### +###.# +###.# +###.# +###.# +#.#.# +..... + +##### +#.##. +#.##. +#.#.. +..#.. +..... +..... + +..... +..... +..... +..#.. +..#.. +.###. +##### + +..... +....# +...## +.#.## +.#.## +##.## +##### + +##### +##### +#.#.# +#.#.# +#.#.. +#.... +..... + +##### +####. +###.. +.##.. +.#... +..... +..... + +##### +.###. +..##. +..##. +...#. +..... +..... + +..... +..... +..... +....# +#.#.# +##### +##### + +..... +...#. +...#. +...#. +#.##. +##### +##### + +##### +##### +##### +.##.# +.##.# +..#.. +..... + +##### +##### +##.## +.#..# +.#... +..... +..... + +##### +#.### +..#.# +..#.. +..#.. +..... +..... + +..... +..... +..... +#.... +#..#. +##.#. +##### + +##### +##### +##.## +##..# +##..# +.#..# +..... + +..... +..... +..#.. +#.#.# +###.# +###.# +##### + +..... +.#..# +.#.## +.#.## +.#.## +##### +##### + +..... +..... +..#.. +..##. +.###. +####. +##### + +##### +.#.## +.#.## +.#.#. +.#.#. +.#... +..... + +..... +#.... +#.... +#.... +#.#.# +###.# +##### + +##### +##### +.#### +.##.# +.#..# +.#... +..... + +..... +..... +...#. +...#. +...#. +.#.#. +##### + +##### +##### +##.## +#...# +..... +..... +..... + +##### +##### +####. +#.##. +#..#. +#.... +..... + +..... +.#.#. +.###. +####. +####. +##### +##### + +..... +#.... +#.... +#.... +#.... +#.#.# +##### + +..... +..... +..... +.#... +###.# +##### +##### + +..... +..#.. +..##. +..### +..### +.#### +##### + +..... +..... +.#... +.#... +.#..# +###.# +##### + +..... +..... +#.... +#.#.# +#.### +#.### +##### + +..... +..... +...#. +...#. +..##. +.###. +##### + +..... +..... +..#.. +..##. +#.##. +####. +##### + +..... +.#..# +.##.# +##### +##### +##### +##### + +..... +..#.. +.##.. +.###. +##### +##### +##### + +##### +####. +###.. +##... +##... +#.... +..... + +..... +..#.. +#.#.# +#.#.# +###.# +###.# +##### + +##### +##### +####. +#.#.. +#.#.. +..... +..... + +..... +#.#.. +###.. +####. +##### +##### +##### + +##### +##### +###.# +##..# +##..# +#...# +..... + +..... +.#... +.#... +.#... +.##.# +.##.# +##### + +##### +####. +####. +#.##. +#.##. +#..#. +..... + +##### +##### +#.#.# +#.#.# +#.#.. +#.#.. +..... + +..... +..... +#..#. +##.#. +##.#. +##.#. +##### + +..... +....# +....# +.#..# +.#..# +##.## +##### + +##### +##### +#.##. +...#. +...#. +..... +..... + +##### +.#### +.#### +.#### +.#.#. +.#.#. +..... + +..... +..#.. +#.#.. +#.#.# +#.#.# +#.### +##### + +##### +.#### +.#### +.#.#. +...#. +..... +..... + +##### +###.# +#.#.# +..#.# +..#.. +..... +..... + +##### +##.## +##.#. +.#.#. +.#... +..... +..... + +..... +..#.# +.##.# +##### +##### +##### +##### + +##### +##### +#.### +...## +...#. +...#. +..... + +##### +#.### +#.#.# +#.... +#.... +..... +..... + +##### +.#### +.##.# +..#.# +..#.. +..#.. +..... + +..... +#.... +#...# +#..## +##.## +##### +##### + +##### +.##.# +.##.. +.##.. +.#... +.#... +..... + +..... +..#.. +..#.# +..#.# +#.### +##### +##### + +##### +####. +####. +#.##. +#..#. +...#. +..... + +..... +#.... +#.... +#.#.. +###.. +###.# +##### + +##### +.##.# +.#... +.#... +.#... +..... +..... + +..... +..#.. +..#.. +..##. +..##. +#.##. +##### + +##### +#.### +#.##. +#.##. +#.#.. +..#.. +..... + +..... +.#.#. +.#.#. +.###. +####. +####. +##### + +##### +.##.# +.##.. +.##.. +.##.. +.#... +..... + +..... +...#. +...#. +..### +.#### +##### +##### + +..... +..... +#..#. +#.##. +#.##. +####. +##### + +..... +..... +....# +..#.# +.##.# +.##.# +##### + +##### +#.### +#.### +#..#. +..... +..... +..... + +..... +.#... +.#... +##..# +##..# +###.# +##### + +..... +.#... +.#... +.#.#. +.###. +.###. +##### + +..... +..... +....# +.#..# +.##.# +##### +##### + +##### +##### +##### +#.#.# +#.#.# +....# +..... + +##### +##### +##.#. +##.#. +##.#. +.#.#. +..... + +..... +..#.. +..#.. +#.#.. +#.#.# +##### +##### + +..... +...#. +.#.#. +##.#. +##.## +##.## +##### + +..... +#..#. +#.##. +#.##. +####. +####. +##### + +..... +#.... +#.#.. +###.. +####. +####. +##### + +..... +..... +....# +.#..# +.#.## +.#.## +##### + +..... +..... +..... +.#..# +.#.## +.#### +##### + +..... +#..#. +#..#. +#..#. +#..#. +##.#. +##### + +##### +#.### +#.### +#.##. +..##. +...#. +..... + +..... +.#... +.##.. +.##.# +.#### +.#### +##### + +##### +#.### +#.### +..#.# +..... +..... +..... + +##### +##### +.##.# +.##.# +.#..# +....# +..... + +..... +#.#.. +###.. +###.. +###.# +###.# +##### + +##### +.#### +.#### +.#.## +...#. +...#. +..... + +##### +#.### +#.### +..##. +..##. +..#.. +..... + +##### +##.## +##.## +##.#. +.#.#. +.#... +..... + +##### +#.### +#.##. +#..#. +...#. +..... +..... + +##### +##### +#.#.# +#.#.. +#.#.. +#.... +..... + +..... +..... +..#.. +.###. +####. +####. +##### + +..... +..... +...#. +.#.#. +.###. +####. +##### + +..... +..#.. +..#.. +..##. +#.### +#.### +##### + +##### +.#### +.#.## +.#.## +.#.#. +.#... +..... + +##### +#.#.# +#.#.# +..#.# +....# +..... +..... + +..... +..... +#.... +#.#.. +####. +##### +##### + +..... +#.... +##... +##... +###.# +##### +##### + +##### +##### +.#### +.#.#. +...#. +...#. +..... + +##### +.#### +.##.# +.##.. +.#... +.#... +..... + +..... +...#. +...#. +.#.## +.#### +.#### +##### + +##### +##.## +#..#. +...#. +...#. +...#. +..... + +..... +#.... +#...# +#...# +##..# +###.# +##### + +..... +#.... +#.#.. +###.. +###.# +##### +##### + +..... +#..#. +#..#. +#.##. +#.##. +##### +##### + +..... +..... +....# +..#.# +#.### +##### +##### + +##### +##### +##### +##### +.#### +..#.# +..... + +##### +##### +#.### +#..#. +...#. +...#. +..... + +..... +.#.#. +.#.#. +.#.#. +.#### +.#### +##### + +..... +..... +...#. +#.### +#.### +##### +##### + +##### +##.#. +##.#. +##... +.#... +.#... +..... + +##### +#.### +#.### +#..## +#..## +#...# +..... + +##### +#.#.# +....# +....# +....# +..... +..... + +..... +..... +..... +..... +...#. +#.##. +##### + +##### +##### +##### +#.##. +#.##. +#.#.. +..... + +##### +##### +.#### +.##.# +..#.# +....# +..... + +..... +..... +..#.# +..#.# +.#### +.#### +##### + +##### +##### +###.# +##... +##... +#.... +..... + +..... +..... +..... +#.... +#.... +##.#. +##### + +##### +.###. +..##. +..##. +..#.. +..#.. +..... + +..... +..... +..#.. +#.#.. +#.##. +##### +##### + +##### +##### +.##.# +.#..# +..... +..... +..... + +##### +##### +##### +#.##. +#..#. +#..#. +..... + +..... +..... +..... +.#.#. +.#.#. +##### +##### + +..... +#.#.. +#.#.# +#.#.# +###.# +##### +##### + +..... +.#.#. +##.#. +##.## +##### +##### +##### + +##### +#.### +#.### +#.#.# +#.#.# +#...# +..... + +##### +#.#.# +..#.# +..#.. +..#.. +..... +..... + +..... +..... +..#.. +.###. +.#### +##### +##### + +##### +##.## +##..# +##..# +.#... +.#... +..... + +##### +#.#.# +#.... +#.... +#.... +..... +..... + +##### +.#### +.#### +.#### +.###. +.#.#. +..... + +..... +..... +..... +..#.. +..#.. +#.#.# +##### + +##### +####. +##.#. +.#.#. +.#.#. +.#.#. +..... + +..... +....# +.#..# +###.# +###.# +###.# +##### + +..... +...#. +..### +..### +.#### +.#### +##### + +..... +..... +...#. +.#.#. +.#.## +.#### +##### + +##### +###.# +##..# +#.... +#.... +#.... +..... + +##### +##### +##.## +.#.#. +...#. +..... +..... + +..... +#..#. +##.#. +##.## +##### +##### +##### + +##### +####. +#.##. +#.##. +#.##. +#..#. +..... + +..... +.#... +.#... +.#... +##..# +###.# +##### + +..... +..... +..... +...#. +.#.#. +##.#. +##### + +##### +##### +#.#.# +#.#.# +..#.. +..... +..... + +..... +.#... +##.#. +##.## +##.## +##### +##### + +##### +#.#.# +#.#.# +..#.. +..... +..... +..... + +##### +##### +#.#.# +#.#.# +#.#.# +#.#.. +..... + +..... +..... +..... +.#... +##..# +##.## +##### + +##### +##.#. +##.#. +##.#. +#..#. +..... +..... + +..... +..... +....# +..#.# +.#### +.#### +##### + +..... +..... +....# +#...# +##..# +##.## +##### + +..... +....# +....# +.#..# +.#..# +###.# +##### + +..... +.#..# +.#..# +##.## +##.## +##### +##### + +..... +..... +#.... +#.#.. +#.#.. +#.#.# +##### + +..... +....# +#...# +##..# +##.## +##.## +##### + +..... +.#... +###.. +###.. +###.# +###.# +##### + +..... +..... +..... +..... +.#... +.##.# +##### + +##### +#.### +#.### +#..#. +#.... +#.... +..... + +##### +###.# +###.# +###.# +###.. +.#... +..... + +..... +.#.#. +.#### +.#### +.#### +.#### +##### + +##### +##### +####. +##.#. +#..#. +#.... +..... + +..... +....# +#.#.# +###.# +###.# +##### +##### + +..... +...#. +...#. +#..#. +#..## +#.### +##### + +..... +..... +..#.. +..#.. +.##.# +##### +##### + +..... +...#. +...#. +..### +..### +.#### +##### + +..... +..... +.#.#. +.###. +.###. +##### +##### + +..... +..... +.#... +.##.. +.##.. +.###. +##### + +##### +#.### +..### +..#.# +..... +..... +..... + +..... +....# +..#.# +#.#.# +#.#.# +#.#.# +##### + +..... +..... +#.#.# +#.#.# +#.#.# +#.### +##### + +##### +####. +####. +####. +.###. +.#.#. +..... + +..... +..... +#.... +#.... +##.#. +##.## +##### + +##### +##### +.#.#. +.#.#. +...#. +...#. +..... + +..... +..... +..... +#..#. +#..#. +##.#. +##### + +..... +....# +..#.# +..#.# +..#.# +#.#.# +##### + +##### +###.# +##... +##... +##... +#.... +..... + +..... +..#.. +..#.# +#.#.# +#.### +##### +##### + +..... +..... +#.#.. +#.#.. +#.#.. +#.##. +##### + +##### +##### +.#.## +.#..# +....# +....# +..... + +..... +.#.#. +##.## +##.## +##.## +##### +##### + +..... +.#... +.#... +##.#. +##.## +##### +##### + +..... +.#.#. +##.#. +##.#. +####. +##### +##### + +..... +..... +..#.# +.#### +.#### +##### +##### + +..... +#...# +#...# +##..# +###.# +###.# +##### + +##### +.#.## +.#.## +.#..# +....# +..... +..... + +##### +.#.## +.#.#. +.#.#. +..... +..... +..... + +..... +..... +.#... +###.. +###.. +###.# +##### + +..... +.#.#. +.#.## +.#.## +.#.## +##### +##### + +..... +....# +....# +....# +#..## +#.### +##### + +..... +...#. +...#. +#.### +##### +##### +##### + +##### +#.### +#.### +..### +..##. +..#.. +..... + +..... +..... +....# +....# +..#.# +#.### +##### + +..... +#..#. +#..## +#.### +#.### +##### +##### + +##### +####. +####. +##.#. +.#... +..... +..... + +..... +..... +..#.. +#.##. +##### +##### +##### + +..... +#.... +#.#.# +#.#.# +###.# +###.# +##### + +..... +.#..# +.#..# +.#.## +.#### +##### +##### + +##### +##### +#.##. +#.##. +#.#.. +..#.. +..... + +##### +##### +##### +##### +##.## +#..#. +..... + +##### +.#### +.#### +.#### +..##. +..#.. +..... + +##### +##### +.#.#. +.#.#. +.#.#. +.#.#. +..... + +..... +#...# +##..# +###.# +###.# +##### +##### + +##### +#.### +#.#.# +#.#.# +#.... +#.... +..... + +##### +#.##. +#.#.. +#.#.. +#.... +..... +..... + +..... +....# +..#.# +..### +#.### +#.### +##### + +..... +.#... +.##.# +.##.# +##### +##### +##### + +..... +..... +..... +.#..# +.##.# +.##.# +##### + +##### +.#### +.###. +.###. +..#.. +..... +..... + +##### +##### +####. +.###. +.###. +..#.. +..... + +##### +##### +#.### +#.##. +#.##. +#.#.. +..... + +##### +#.##. +#.##. +#.#.. +#.... +#.... +..... + +##### +#.### +#.##. +#..#. +#..#. +#..#. +..... + +..... +#.... +#.... +#.... +#...# +##.## +##### + +..... +#.#.. +#.#.. +#.#.. +####. +##### +##### + +..... +#.#.. +#.#.. +#.#.. +#.##. +#.### +##### + +..... +..... +..#.. +#.#.. +#.#.. +###.# +##### + +..... +#...# +#...# +#...# +##.## +##.## +##### + +##### +##### +##.## +##.## +##.## +#...# +..... + +..... +....# +....# +#...# +#...# +#.#.# +##### + +..... +..... +#..#. +#..#. +##.#. +##.#. +##### + +..... +...#. +...#. +#..## +#.### +##### +##### + +##### +#.### +#.### +..### +..##. +...#. +..... + +##### +.#### +.#.## +...#. +...#. +..... +..... + +##### +##.#. +##.#. +.#.#. +...#. +...#. +..... + +..... +..... +#.#.. +#.##. +####. +##### +##### + +..... +.#.#. +##.#. +####. +####. +##### +##### + +##### +##### +.#### +.##.# +.#... +.#... +..... + +..... +.#... +##... +##.#. +####. +##### +##### + +##### +#.##. +#.##. +#.##. +#.#.. +..... +..... + +##### +##### +#.#.# +#.... +#.... +#.... +..... + +##### +##### +.#### +.#### +..#.# +..#.# +..... + +..... +..... +#.... +#..#. +#..#. +#.### +##### + +##### +##### +##### +##### +###.# +#.#.# +..... + +..... +.#... +.#... +.#.#. +.#### +.#### +##### + +##### +##### +##### +.###. +..##. +...#. +..... + +..... +...#. +...#. +#.##. +##### +##### +##### + +##### +###.# +.##.# +..#.# +..#.# +..#.# +..... + +##### +####. +.#.#. +...#. +...#. +...#. +..... + +##### +##.## +##.#. +.#.#. +.#.#. +..... +..... + +##### +##.## +##..# +##... +#.... +#.... +..... + +##### +.#### +.###. +..##. +..##. +...#. +..... + +##### +#.#.# +#.#.# +#.#.# +#.#.# +..... +..... + +..... +.#... +##.#. +##.#. +##### +##### +##### + +..... +..... +....# +..#.# +..#.# +.##.# +##### + +##### +##### +####. +#.##. +#.#.. +#.... +..... + +##### +##### +.###. +.#.#. +.#... +.#... +..... + +..... +..#.. +..#.. +..##. +.#### +##### +##### + +..... +..... +.#... +.#.#. +##.#. +##.## +##### + +##### +##### +##.#. +##.#. +#.... +..... +..... + +##### +##.## +#..## +#..## +...## +....# +..... + +##### +###.# +###.# +.##.# +.#..# +.#..# +..... + +..... +#.... +#.... +#.#.. +#.##. +####. +##### + +##### +##.## +##.## +#...# +..... +..... +..... + +##### +#.#.# +#...# +#...# +....# +....# +..... + +..... +.#... +.#.#. +.#.#. +.#.## +.#### +##### + +..... +..... +#.... +##.#. +##.#. +####. +##### + +##### +##### +####. +.###. +.#.#. +.#.#. +..... + +..... +.#.#. +.#.## +.#.## +.#.## +##.## +##### + +##### +##.## +##.## +.#.## +.#.## +....# +..... + +..... +..#.. +..#.. +..##. +..##. +.#### +##### + +##### +#.#.# +#.#.# +#...# +#.... +#.... +..... + +..... +..... +....# +#...# +##..# +###.# +##### + +##### +##### +#.### +#.### +#.##. +#..#. +..... + +##### +#.### +..### +..#.# +..#.# +..... +..... + +##### +###.# +###.# +##..# +#.... +..... +..... + +##### +##### +.#.## +...## +...## +....# +..... + +..... +.#.#. +.###. +##### +##### +##### +##### + +##### +##### +###.# +.#... +.#... +.#... +..... + +##### +#.### +#.#.# +#.#.# +#.#.. +..... +..... + +##### +##### +##.## +##.## +#...# +#...# +..... + +##### +###.# +###.. +.#... +..... +..... +..... + +##### +##### +####. +##.#. +##.#. +#.... +..... + +..... +...#. +...## +..### +#.### +##### +##### + +##### +.#### +.#.## +.#.## +....# +....# +..... + +..... +#...# +#..## +#..## +#.### +#.### +##### + +..... +..... +#.... +#..#. +#.##. +#.### +##### + +..... +..... +.#.#. +.#### +##### +##### +##### + +..... +..... +..... +.#... +.#..# +.#.## +##### + +..... +..... +#..#. +#..#. +##.#. +####. +##### + +##### +##.## +##.## +##.## +##..# +#.... +..... + +##### +##.## +.#.## +.#.#. +.#.#. +.#... +..... + +..... +#..#. +#..## +#.### +#.### +#.### +##### + +..... +.#... +.#.#. +.#.## +.#.## +.#### +##### + +##### +.#.#. +.#.#. +.#.#. +.#.#. +..... +..... + +..... +..... +#.... +#.... +#..#. +#.##. +##### + +##### +#.### +#..#. +...#. +..... +..... +..... + +##### +#.#.# +....# +....# +..... +..... +..... + +##### +###.# +.##.# +.##.# +..#.# +....# +..... + +..... +#..#. +#.### +#.### +#.### +#.### +##### + +##### +###.# +.##.# +..#.# +..#.. +..... +..... + +..... +....# +#...# +#.#.# +#.#.# +#.### +##### + +##### +#.### +#.### +#..## +#..#. +#.... +..... + +##### +##.## +##.## +.#.## +.#.## +...#. +..... + +..... +..... +....# +#...# +#...# +#.#.# +##### + +##### +##.## +##.## +##..# +#...# +....# +..... + +##### +.#.## +...## +....# +....# +..... +..... + +..... +.#... +.#..# +.#..# +.#..# +##.## +##### + +##### +.#### +.###. +.#.#. +...#. +...#. +..... + +##### +.#### +.#### +.#.## +.#..# +..... +..... + +##### +###.# +#.#.# +#...# +#...# +..... +..... + +..... +...#. +.#.#. +.#### +.#### +.#### +##### + +..... +..... +..#.. +#.#.. +###.. +###.# +##### + +..... +#..#. +#..#. +#..## +#.### +#.### +##### + +..... +..#.. +..#.# +#.#.# +#.#.# +###.# +##### + +..... +..... +.#.#. +.#.#. +.#.## +.#.## +##### + +##### +##### +##.## +#...# +....# +..... +..... + +..... +.#... +##..# +##..# +##.## +##.## +##### + +##### +.##.# +.##.# +.##.# +..#.# +..#.# +..... + +##### +.##.# +.##.. +.#... +..... +..... +..... + +..... +#.#.# +#.#.# +#.#.# +###.# +###.# +##### + +..... +..... +..#.. +..#.# +..### +#.### +##### + +##### +##### +##### +##.## +.#.## +.#.#. +..... + +##### +####. +####. +.#.#. +.#.#. +.#... +..... + +..... +..... +.#.#. +##.#. +##.## +##.## +##### + +..... +#..#. +#..#. +#..#. +#.### +##### +##### + +##### +##.## +##.## +.#.#. +.#.#. +..... +..... + +##### +.#.## +...## +...#. +...#. +...#. +..... + +..... +.#... +.##.# +.##.# +###.# +##### +##### + +..... +....# +...## +...## +..### +.#### +##### + +##### +##### +##### +##### +###.# +.#... +..... + +##### +###.# +###.# +.##.# +.##.# +.#... +..... + +..... +..... +..#.. +#.#.. +###.. +####. +##### + +##### +##.## +##.## +.#.## +...## +...#. +..... + +##### +##### +##### +##.## +#..#. +..... +..... + +##### +####. +.###. +..##. +..#.. +..... +..... + +..... +..... +..#.. +..##. +#.##. +#.### +##### + +##### +##### +##### +#.### +#..#. +..... +..... + +..... +...#. +...#. +...#. +.#.## +##.## +##### + +..... +....# +....# +.#..# +.##.# +.#### +##### + +##### +####. +####. +#.##. +#..#. +..... +..... + +..... +...#. +.#.#. +.#.#. +.#.## +.#.## +##### + +##### +#.### +..#.# +..#.. +..#.. +..#.. +..... + +##### +##### +####. +##.#. +#..#. +...#. +..... + +##### +#.### +#..## +...## +....# +....# +..... + +##### +##### +##.#. +##.#. +##... +.#... +..... + +##### +.#### +.#.## +...#. +...#. +...#. +..... + +..... +..... +#...# +#.#.# +###.# +###.# +##### + +##### +.#### +.#### +.#.## +....# +..... +..... + +##### +##### +#.### +..##. +...#. +..... +..... + +##### +.#### +.#.## +.#.## +.#.## +.#..# +..... + +..... +....# +..#.# +..#.# +.##.# +##### +##### + +..... +...#. +...#. +#..#. +#..#. +#.##. +##### + +##### +#.### +..##. +..#.. +..#.. +..#.. +..... + +##### +###.# +.##.# +.##.# +.##.# +..#.# +..... + +##### +###.# +###.# +###.. +##... +#.... +..... + +..... +#.#.. +#.#.# +#.#.# +#.#.# +##### +##### + +..... +..... +.#... +##... +##..# +###.# +##### + +##### +##### +.###. +.#.#. +.#.#. +.#.#. +..... + +..... +.#... +.#... +##..# +###.# +##### +##### + +..... +..... +..... +..... +..#.# +.##.# +##### + +##### +##.## +.#..# +.#..# +....# +..... +..... + +..... +..... +.#.#. +##### +##### +##### +##### + +..... +.#... +.#... +##.#. +##.#. +##### +##### + +..... +#.... +#.#.. +####. +####. +##### +##### + +..... +..... +#.#.. +###.. +####. +####. +##### + +##### +###.# +##..# +##..# +##..# +#.... +..... + +..... +..... +#...# +#.#.# +#.#.# +###.# +##### + +##### +##.## +.#.## +.#.## +.#..# +..... +..... + +##### +##.#. +#.... +..... +..... +..... +..... + +..... +..... +..... +.#..# +.#..# +.#.## +##### + +..... +.#.#. +.#.#. +.#.#. +.#.#. +####. +##### + +##### +##.#. +##.#. +.#.#. +.#.#. +.#.#. +..... + +##### +###.# +###.# +###.# +.#..# +.#... +..... + +##### +##### +##.## +#...# +#.... +..... +..... + +..... +..#.. +..#.. +#.#.. +#.##. +####. +##### + +..... +.#... +##... +##... +##..# +##.## +##### + +..... +...#. +...#. +...## +...## +#.### +##### + +##### +##### +##### +#.#.# +#.#.# +..#.# +..... + +..... +..#.. +.##.. +###.. +####. +####. +##### + +##### +#.### +..#.# +..#.# +....# +..... +..... + +..... +.#... +##.#. +##.#. +##.## +##### +##### \ No newline at end of file diff --git a/src/test/kotlin/adventofcode/common/spatial/Grid2dSpec.kt b/src/test/kotlin/adventofcode/common/spatial/Grid2dSpec.kt index 8563e26..5f5027c 100644 --- a/src/test/kotlin/adventofcode/common/spatial/Grid2dSpec.kt +++ b/src/test/kotlin/adventofcode/common/spatial/Grid2dSpec.kt @@ -45,6 +45,45 @@ class Grid2dSpec : FreeSpec({ } } + "rowAt" - { + "returns the contents of the row with the given index" { + grid.rowAt(1) shouldContainExactly listOf('D', 'E', 'F') + } + + "throws if the index is outside the grid" { + shouldThrow { grid.rowAt(-1) } + shouldThrow { grid.rowAt(grid.rows + 1) } + } + } + + "columnAt" - { + "returns the contents of the column with the given index" { + grid.columnAt(1) shouldContainExactly listOf('B', 'E', 'H') + } + + "throws if the index is outside the grid" { + shouldThrow { grid.columnAt(-1) } + shouldThrow { grid.columnAt(grid.columnsInRow(0) + 1) } + } + } + + "rows" - { + "returns the values of the grid as a List>" { + grid.rows() shouldContainExactly grid.values + } + } + + "columns" - { + "returns the columns of the grid as a List>" { + grid.columns() shouldContainExactly + listOf( + listOf('A', 'D', 'G'), + listOf('B', 'E', 'H'), + listOf('C', 'F', 'I'), + ) + } + } + "operator contains" - { "by value" - { "returns `true` if the grid contains that value" { diff --git a/src/test/kotlin/adventofcode/year2024/Day25CodeChronicleSpec.kt b/src/test/kotlin/adventofcode/year2024/Day25CodeChronicleSpec.kt new file mode 100644 index 0000000..417f54e --- /dev/null +++ b/src/test/kotlin/adventofcode/year2024/Day25CodeChronicleSpec.kt @@ -0,0 +1,5 @@ +package adventofcode.year2024 + +import adventofcode.PuzzleBaseSpec + +class Day25CodeChronicleSpec : PuzzleBaseSpec(3) diff --git a/src/test/resources/inputs/year2024/day25.txt b/src/test/resources/inputs/year2024/day25.txt new file mode 100644 index 0000000..a53fe9b --- /dev/null +++ b/src/test/resources/inputs/year2024/day25.txt @@ -0,0 +1,39 @@ +##### +.#### +.#### +.#### +.#.#. +.#... +..... + +##### +##.## +.#.## +...## +...#. +...#. +..... + +..... +#.... +#.... +#...# +#.#.# +#.### +##### + +..... +..... +#.#.. +###.. +###.# +###.# +##### + +..... +..... +..... +#.... +#.#.. +#.#.# +##### \ No newline at end of file