diff --git a/README.md b/README.md index e9c09e8..b45e0b7 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ | 2021 | ★ | ★ | ★ | ★ | ★ | ★ | ★ | ★ | ★ | ★ | ★ | | ★ | ★ | | | | | | | | | | | | 26 | | 2022 | ★ | ★ | ★ | ★ | ★ | ★ | ★ | ★ | ★ | ★ | ★ | ★ | ★ | | | | | | | | ☆ | | | | ☆ | 28 | | 2023 | ★ | ★ | ★ | ★ | ☆ | ★ | ☆ | | | | | | | | | | | | | | | | | | | 12 | -| 2024 | ★ | ★ | ★ | ★ | ★ | ★ | ★ | ★ | ★ | ★ | ★ | ★ | ★ | ★ | | ☆ | ★ | | ★ | | | | | | | 33 | +| 2024 | ★ | ★ | ★ | ★ | ★ | ★ | ★ | ★ | ★ | ★ | ★ | ★ | ★ | ★ | | ☆ | ★ | | ★ | ☆ | | | | | | 34 | ## 🛷 How to run @@ -181,6 +181,7 @@ e.g. `HandyHaversacks`)* | | 16 | [Reindeer Maze](https://adventofcode.com/2024/day/16) | [[Code](src/main/kotlin/adventofcode/year2024/Day16ReindeerMaze.kt)] [[Test](src/test/kotlin/adventofcode/year2024/Day16ReindeerMazeSpec.kt)] | `98484` | | | | 17 | [Chronospatial Computer](https://adventofcode.com/2024/day/17) | [[Code](src/main/kotlin/adventofcode/year2024/Day17ChronospatialComputer.kt)] [[Test](src/test/kotlin/adventofcode/year2024/Day17ChronospatialComputerSpec.kt)] | `5,1,3,4,3,7,2,1,7` | `216584205979245` | | | 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` | | ## 🕯️ Useful commands diff --git a/src/main/kotlin/adventofcode/common/spatial/Point2d.kt b/src/main/kotlin/adventofcode/common/spatial/Point2d.kt index 088d9f3..eaed91a 100644 --- a/src/main/kotlin/adventofcode/common/spatial/Point2d.kt +++ b/src/main/kotlin/adventofcode/common/spatial/Point2d.kt @@ -1,5 +1,7 @@ package adventofcode.common.spatial +import kotlin.math.absoluteValue + data class Point2d( val x: Long, val y: Long, @@ -44,6 +46,8 @@ data class Point2d( } .map { direction -> this + direction } .toSet() + + infix fun distanceTo(other: Point2d): Long = (x - other.x).absoluteValue + (y - other.y).absoluteValue } val NORTH = Point2d(0, -1) diff --git a/src/main/kotlin/adventofcode/year2024/Day20RaceCondition.kt b/src/main/kotlin/adventofcode/year2024/Day20RaceCondition.kt new file mode 100644 index 0000000..5b3f3a3 --- /dev/null +++ b/src/main/kotlin/adventofcode/year2024/Day20RaceCondition.kt @@ -0,0 +1,41 @@ +package adventofcode.year2024 + +import adventofcode.Puzzle +import adventofcode.PuzzleInput +import adventofcode.common.spatial.Grid2d +import adventofcode.common.spatial.Point2d + +class Day20RaceCondition(customInput: PuzzleInput? = null) : Puzzle(customInput) { + private val racetrack by lazy { input.racketrack() } + + override fun partOne() = racetrack.findCheats(2) + + companion object { + private const val MINIMUM_SAVINGS = 100 + + private fun String.racketrack(): List { + val grid = Grid2d(this) + val path = mutableListOf(grid['S']) + + while (path.last() != grid['E']) { + val next = + grid.neighborsOf(path.last()) + .filterNot { neighbor -> neighbor == path.getOrNull(path.lastIndex - 1) } + .filterNot { neighbor -> grid[neighbor] == '#' } + .first() + + path.add(next) + } + + return path.toList() + } + + private fun List.findCheats(time: Int) = + indices.sumOf { start -> + (start + MINIMUM_SAVINGS..lastIndex).count { end -> + val distance = this[start] distanceTo this[end] + (distance <= time) && (distance <= end - start - MINIMUM_SAVINGS) + } + } + } +} diff --git a/src/main/resources/inputs/year2024/day20.txt b/src/main/resources/inputs/year2024/day20.txt new file mode 100644 index 0000000..a497bdb --- /dev/null +++ b/src/main/resources/inputs/year2024/day20.txt @@ -0,0 +1,141 @@ +############################################################################################################################################# +#...#...#.........#...#...#...#...#.......#.........#.....###.........#...#...#...#...#...###.......#.........#.....#...#.....#...#...#...### +#.#.#.#.#.#######.#.#.#.#.#.#.#.#.#.#####.#.#######.#.###.###.#######.#.#.#.#.#.#.#.#.#.#.###.#####.#.#######.#.###.#.#.#.###.#.#.#.#.#.#.### +#.#.#.#.#.......#.#.#...#.#.#.#.#.#.#.....#.......#.#.#...#...#...#...#.#...#...#...#...#...#.#.....#.#...#...#.#...#.#.#...#...#.#.#.#.#...# +#.#.#.#.#######.#.#.#####.#.#.#.#.#.#.###########.#.#.#.###.###.#.#.###.###################.#.#.#####.#.#.#.###.#.###.#.###.#####.#.#.#.###.# +#.#.#.#...###...#.#.....#.#.#...#...#.#...###...#.#...#...#...#.#.#...#.....#.....#...#.....#.#.#...#.#.#...###.#.###.#.....#.....#.#.#.#...# +#.#.#.###.###.###.#####.#.#.#########.#.#.###.#.#.#######.###.#.#.###.#####.#.###.#.#.#.#####.#.#.#.#.#.#######.#.###.#######.#####.#.#.#.### +#.#...#...#...#...###...#...#.........#.#.#...#.#.#.......###.#.#...#.......#...#.#.#.#...#...#...#...#.....#...#...#.......#.#...#.#...#...# +#.#####.###.###.#####.#######.#########.#.#.###.#.#.#########.#.###.###########.#.#.#.###.#.###############.#.#####.#######.#.#.#.#.#######.# +#.#...#...#...#.###...#.....#.###...#...#.#...#.#.#.#.......#...###...#.........#...#.....#.........#.......#...#...#...###.#.#.#.#.#.......# +#.#.#.###.###.#.###.###.###.#.###.#.#.###.###.#.#.#.#.#####.#########.#.###########################.#.#########.#.###.#.###.#.#.#.#.#.####### +#.#.#...#.#...#...#.#...###.#.....#.#.#...#...#.#.#.#...#...#.........#.###.......#...#...#...#...#.#.#...#...#.#.#...#.#...#...#...#.......# +#.#.###.#.#.#####.#.#.#####.#######.#.#.###.###.#.#.###.#.###.#########.###.#####.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.###.#.#################.# +#...#...#.#.....#.#...#...#.....#...#.#.###...#.#.#.#...#...#.....#.....#...#...#.#.#.#.#...#...#...#...#.#.#.#.#...#...#.#.................# +#####.###.#####.#.#####.#.#####.#.###.#.#####.#.#.#.#.#####.#####.#.#####.###.#.#.#.#.#.#################.#.#.#.#####.###.#.################# +#...#...#.......#.....#.#.#...#.#.#...#...#...#...#...#.....#.....#...#...#...#...#.#.#.............#.....#.#.#...#...#...#.#...#...........# +#.#.###.#############.#.#.#.#.#.#.#.#####.#.###########.#####.#######.#.###.#######.#.#############.#.#####.#.###.#.###.###.#.#.#.#########.# +#.#.###.#...........#.#.#.#.#...#.#...#...#...#...#...#.#...#.......#.#.#...#.....#.#...###.....#...#.#...#.#.#...#...#.#...#.#.#.#.........# +#.#.###.#.#########.#.#.#.#.#####.###.#.#####.#.#.#.#.#.#.#.#######.#.#.#.###.###.#.###.###.###.#.###.#.#.#.#.#.#####.#.#.###.#.#.#.######### +#.#.....#.###.......#.#.#.#.#.....#...#.#...#...#...#.#.#.#.#.....#.#.#.#.###...#.#...#.....#...#...#...#.#.#.#...#...#.#.###.#.#.#...#.....# +#.#######.###.#######.#.#.#.#.#####.###.#.#.#########.#.#.#.#.###.#.#.#.#.#####.#.###.#######.#####.#####.#.#.###.#.###.#.###.#.#.###.#.###.# +#.....#...#...#.....#...#...#...#...#...#.#...#.....#.#...#.#...#...#...#...#...#.#...#.......#...#.....#.#.#...#.#.....#...#.#.#.#...#.#...# +#####.#.###.###.###.###########.#.###.###.###.#.###.#.#####.###.###########.#.###.#.###.#######.#.#####.#.#.###.#.#########.#.#.#.#.###.#.### +###...#.###.....###...#.......#.#...#.#...#...#...#.#.....#...#.#.....#.....#...#.#.#...###.....#.....#.#.#.#...#.#.........#.#.#.#.#...#...# +###.###.#############.#.#####.#.###.#.#.###.#####.#.#####.###.#.#.###.#.#######.#.#.#.#####.#########.#.#.#.#.###.#.#########.#.#.#.#.#####.# +#...#...#.....#...#...#...#...#.#...#.#.#...#...#.#.#...#.#...#...#...#.....#...#.#.#.....#.........#...#.#.#.....#.........#.#.#.#...#...#.# +#.###.###.###.#.#.#.#####.#.###.#.###.#.#.###.#.#.#.#.#.#.#.#######.#######.#.###.#.#####.#########.#####.#.###############.#.#.#.#####.#.#.# +#...#.###...#.#.#.#.......#...#.#...#...#...#.#.#.#...#...#.#...#...#...#...#...#.#...#...#...#...#.#...#.#.#...............#.#.#.#.....#...# +###.#.#####.#.#.#.###########.#.###.#######.#.#.#.#########.#.#.#.###.#.#.#####.#.###.#.###.#.#.#.#.#.#.#.#.#.###############.#.#.#.######### +#...#.#.....#...#.###...#...#.#.###.#.....#.#.#.#.#.........#.#.#.#...#...#.....#...#.#.###.#.#.#.#...#.#.#.#...#.....#...#...#...#.........# +#.###.#.#########.###.#.#.#.#.#.###.#.###.#.#.#.#.#.#########.#.#.#.#######.#######.#.#.###.#.#.#.#####.#.#.###.#.###.#.#.#.###############.# +#.....#.........#.....#...#...#...#...#...#.#.#.#.#.....#.....#.#.#.#.....#.......#.#.#...#.#.#.#.#...#.#.#.#...#.#...#.#...#.....#.........# +###############.#################.#####.###.#.#.#.#####.#.#####.#.#.#.###.#######.#.#.###.#.#.#.#.#.#.#.#.#.#.###.#.###.#####.###.#.######### +###...###.......#...............#.....#...#.#.#.#...#...#...#...#.#.#.#...###...#.#.#.#...#.#.#.#.#.#.#.#...#.....#.....#...#.#...#.........# +###.#.###.#######.#############.#####.###.#.#.#.###.#.#####.#.###.#.#.#.#####.#.#.#.#.#.###.#.#.#.#.#.#.#################.#.#.#.###########.# +#...#.....#.......#...#.......#.....#.#...#...#.#...#...#...#...#.#.#.#...#...#.#.#.#.#...#.#...#.#.#.#.#.................#...#...#...#...#.# +#.#########.#######.#.#.#####.#####.#.#.#######.#.#####.#.#####.#.#.#.###.#.###.#.#.#.###.#.#####.#.#.#.#.#######################.#.#.#.#.#.# +#...#...#...###.....#.#.....#.#.....#.#.....#...#.#...#.#...#...#.#...###.#...#.#.#.#.#...#.....#.#.#.#.#.........#.............#...#.#.#.#.# +###.#.#.#.#####.#####.#####.#.#.#####.#####.#.###.#.#.#.###.#.###.#######.###.#.#.#.#.#.#######.#.#.#.#.#########.#.###########.#####.#.#.#.# +#...#.#...#.....#...#.......#...#...#...#...#...#...#.#...#.#.#...#.....#.#...#.#.#...#.....#...#.#.#...#.......#...#...........#...#...#.#.# +#.###.#####.#####.#.#############.#.###.#.#####.#####.###.#.#.#.###.###.#.#.###.#.#########.#.###.#.#####.#####.#####.###########.#.#####.#.# +#.....#...#.......#.............#.#...#...#...#.#.....#...#.#.#...#...#...#.#...#.#.........#.###.#.#...#.....#.#...#...#.........#.....#.#.# +#######.#.#####################.#.###.#####.#.#.#.#####.###.#.###.###.#####.#.###.#.#########.###.#.#.#.#####.#.#.#.###.#.#############.#.#.# +###...#.#.#...#...#...........#...#...###...#...#.....#...#.#...#.###.#.....#...#.#.#...#...#...#.#.#.#.......#...#.#...#...#.....#.....#.#.# +###.#.#.#.#.#.#.#.#.#########.#####.#####.###########.###.#.###.#.###.#.#######.#.#.#.#.#.#.###.#.#.#.#############.#.#####.#.###.#.#####.#.# +#...#...#...#.#.#.#...#.....#.#...#.....#.......#...#...#...#...#.#...#.....###...#.#.#.#.#.#...#...#.......#...###...###...#...#...#...#...# +#.###########.#.#.###.#.###.#.#.#.#####.#######.#.#.###.#####.###.#.#######.#######.#.#.#.#.#.#############.#.#.#########.#####.#####.#.##### +#...........#...#...#...###.#...#.#...#.......#.#.#...#...###.....#...#...#.......#.#.#...#.#.#.....#.......#.#.........#.#.....#...#.#.....# +###########.#######.#######.#####.#.#.#######.#.#.###.###.###########.#.#.#######.#.#.#####.#.#.###.#.#######.#########.#.#.#####.#.#.#####.# +#...###...#.....#...#...#...#...#...#.........#.#.###...#.....#.......#.#.....#...#.#.#...#...#.#...#.........#.....#...#.#.#...#.#.#.#.....# +#.#.###.#.#####.#.###.#.#.###.#.###############.#.#####.#####.#.#######.#####.#.###.#.#.#.#####.#.#############.###.#.###.#.#.#.#.#.#.#.##### +#.#.#...#.......#...#.#.#.....#...............#.#.....#.#...#.#.#.....#.#.....#...#...#.#.#.....#.###...#...#...###.#...#.#...#...#...#.....# +#.#.#.#############.#.#.#####################.#.#####.#.#.#.#.#.#.###.#.#.#######.#####.#.#.#####.###.#.#.#.#.#####.###.#.#################.# +#.#.#.............#.#.#.#...#...###...........#.......#.#.#.#.#.#.#...#.#...#...#...#...#.#.....#.....#...#...#...#...#...#.................# +#.#.#############.#.#.#.#.#.#.#.###.###################.#.#.#.#.#.#.###.###.#.#.###.#.###.#####.###############.#.###.#####.################# +#.#...#...#.......#...#...#.#.#...#.......#...#.......#.#.#.#.#.#.#...#...#...#.....#...#.#...#.....#.....#.....#...#.#...#.#...............# +#.###.#.#.#.###############.#.###.#######.#.#.#.#####.#.#.#.#.#.#.###.###.#############.#.#.#.#####.#.###.#.#######.#.#.#.#.#.#############.# +#...#.#.#...#...#.........#.#...#.........#.#...#.....#.#.#.#.#.#...#...#.#.............#...#.......#.###...#.......#.#.#.#...#...#...#.....# +###.#.#.#####.#.#.#######.#.###.###########.#####.#####.#.#.#.#.###.###.#.#.#########################.#######.#######.#.#.#####.#.#.#.#.##### +###.#...#...#.#.#.#.......#.#...#...........#.....#.....#.#...#.#...#...#.#...#...#...#...#...#...#...#.......#...###...#...#...#.#.#.#.....# +###.#####.#.#.#.#.#.#######.#.###.###########.#####.#####.#####.#.###.###.###.#.#.#.#.#.#.#.#.#.#.#.###.#######.#.#########.#.###.#.#.#####.# +#...#...#.#...#...#.......#...#...#...#.....#...###.......###...#...#...#.#...#.#.#.#...#.#.#.#.#.#.###.......#.#.....#####...###.#.#.......# +#.###.#.#.###############.#####.###.#.#.###.###.#############.#####.###.#.#.###.#.#.#####.#.#.#.#.#.#########.#.#####.###########.#.######### +#...#.#...###...#...#...#...#...#...#...#...#...#...#...#...#...#...###...#.....#.#.#.....#.#...#...#.......#...#...#...#.......#...#.......# +###.#.#######.#.#.#.#.#.###.#.###.#######.###.###.#.#.#.#.#.###.#.###############.#.#.#####.#########.#####.#####.#.###.#.#####.#####.#####.# +###...#...#...#...#...#.....#...#.......#...#.....#...#...#...#.#...#.....###...#.#.#...#...#.........#...#.......#.....#.#.....#...#...#...# +#######.#.#.###################.#######.###.#################.#.###.#.###.###.#.#.#.###.#.###.#########.#.###############.#.#####.#.###.#.### +#.......#...#.......#...#.......#.......#...#.....#.......#...#.....#.#...#...#...#.#...#...#...........#.......#...#...#.#.......#.....#...# +#.###########.#####.#.#.#.#######.#######.###.###.#.#####.#.#########.#.###.#######.#.#####.###################.#.#.#.#.#.#################.# +#.....#.......#...#...#...###...#.......#.....###.#.....#...#.....#...#...#...#.....#.......#...................#.#.#.#.#.#.....#...#.....#.# +#####.#.#######.#.###########.#.#######.#########.#####.#####.###.#.#####.###.#.#############.###################.#.#.#.#.#.###.#.#.#.###.#.# +###...#...#.....#.......#...#.#.......#.........#.#.....#...#...#.#.....#...#.#.#.............#...............#...#...#...#...#...#.#...#.#.# +###.#####.#.###########.#.#.#.#######.#########.#.#.#####.#.###.#.#####.###.#.#.#.#############.#############.#.#############.#####.###.#.#.# +#...#.....#.....#.....#...#...#.....#...........#...#...#.#.###.#.#...#.#...#...#...#.....#.....#.............#.#...#...#...#.....#.....#.#.# +#.###.#########.#.###.#########.###.#################.#.#.#.###.#.#.#.#.#.#########.#.###.#.#####.#############.#.#.#.#.#.#.#####.#######.#.# +#.....#...#...#.#...#...#.......###...................#...#.#...#.#.#.#.#.#...#...#.#.#...#.#...#...#...........#.#...#...#.#...#.....###...# +#######.#.#.#.#.###.###.#.#################################.#.###.#.#.#.#.#.#.#.#.#.#.#.###.#.#.###.#.###########.#########.#.#.#####.####### +#.......#...#.#.#...###...#.............#...#...#.....#.....#...#.#.#.#.#.#.#...#.#...#.....#.#.....#.#.....#...#.........#...#...#...#.....# +#.###########.#.#.#########.###########.#.#.#.#.#.###.#.#######.#.#.#.#.#.#.#####.###########.#######.#.###.#.#.#########.#######.#.###.###.# +#.........#...#...#...#.....#...#.....#.#.#.#.#.#...#.#...#...#.#.#.#...#...#.....###S#######.#...#...#...#...#...#.....#.......#.#...#.#...# +#########.#.#######.#.#.#####.#.#.###.#.#.#.#.#.###.#.###.#.#.#.#.#.#########.#######.#######.#.#.#.#####.#######.#.###.#######.#.###.#.#.### +#.........#.......#.#.#.....#.#...#...#...#...#...#.#.#...#.#.#.#.#.#...#...#...#.....#####...#.#.#...###.......#.#.#...#.......#...#...#...# +#.###############.#.#.#####.#.#####.#############.#.#.#.###.#.#.#.#.#.#.#.#.###.#.#########.###.#.###.#########.#.#.#.###.#########.#######.# +#...............#.#.#.#...#.#...#...#...#...#...#...#...#...#...#.#.#.#...#.....#.....#####.....#.....#.....#...#.#.#.....#.......#.........# +###############.#.#.#.#.#.#.###.#.###.#.#.#.#.#.#########.#######.#.#.###############.#################.###.#.###.#.#######.#####.########### +#.......#.......#...#...#.#.....#.....#...#.#.#.#.......#.......#.#.#.....#...#...###...###############...#...###...###...#...#...#...#.....# +#.#####.#.###############.#################.#.#.#.#####.#######.#.#.#####.#.#.#.#.#####.#################.#############.#.###.#.###.#.#.###.# +#.....#.#...............#.###...###...#...#...#.#.#...#...###...#.#.#.....#.#.#.#.#...#...###############.....#.........#.....#.....#...#...# +#####.#.###############.#.###.#.###.#.#.#.#####.#.#.#.###.###.###.#.#.#####.#.#.#.#.#.###.###################.#.#########################.### +#.....#.###...#...###...#.....#.....#...#.......#...#...#...#...#.#.#.#...#.#.#.#...#.###.#############E....#...#...#.....#.....#...#...#...# +#.#####.###.#.#.#.###.#################################.###.###.#.#.#.#.#.#.#.#.#####.###.#################.#####.#.#.###.#.###.#.#.#.#.###.# +#.#...#.....#...#.....#...#.........#.....#.....###...#...#.#...#...#...#.#.#.#.....#.....###########.....#.......#...###...###.#.#...#.....# +#.#.#.#################.#.#.#######.#.###.#.###.###.#.###.#.#.###########.#.#.#####.#################.###.#####################.#.########### +#...#.#...........#...#.#.#.###...#...#...#.#...#...#.#...#...#.......#...#.#.....#.#...........#.....###...#.....#.....###...#...#...#.....# +#####.#.#########.#.#.#.#.#.###.#.#####.###.#.###.###.#.#######.#####.#.###.#####.#.#.#########.#.#########.#.###.#.###.###.#.#####.#.#.###.# +#.....#.#.........#.#.#.#.#.#...#.#...#...#.#.#...#...#.......#.#...#...#...#...#.#.#.#...#.....#...#.......#.#...#.#...#...#...#...#...#...# +#.#####.#.#########.#.#.#.#.#.###.#.#.###.#.#.#.###.#########.#.#.#.#####.###.#.#.#.#.#.#.#.#######.#.#######.#.###.#.###.#####.#.#######.### +#.....#.#.....#.....#...#...#...#...#.....#.#.#...#.#.....#...#...#...#...#...#...#...#.#.#.........#.........#.....#...#.#.....#.#...#...### +#####.#.#####.#.###############.###########.#.###.#.#.###.#.#########.#.###.###########.#.#############################.#.#.#####.#.#.#.##### +#...#...#.....#.#.......###...#.........###.#.###.#.#...#.#...#.......#...#.....#...#...#...#...#.............#...#...#...#.#.....#.#...#...# +#.#.#####.#####.#.#####.###.#.#########.###.#.###.#.###.#.###.#.#########.#####.#.#.#.#####.#.#.#.###########.#.#.#.#.#####.#.#####.#####.#.# +#.#.......#...#.#.#...#.....#.....#.....#...#...#.#.#...#.#...#.#.....#...#.....#.#.#.....#.#.#.#.....#.....#.#.#...#.....#...#...#.......#.# +#.#########.#.#.#.#.#.###########.#.#####.#####.#.#.#.###.#.###.#.###.#.###.#####.#.#####.#.#.#.#####.#.###.#.#.#########.#####.#.#########.# +#.#.......#.#.#.#.#.#...#.......#...#...#.....#.#.#.#.#...#...#.#.#...#...#.#...#.#.#...#.#.#.#.#...#...#...#.#.........#.#...#.#.#...#...#.# +#.#.#####.#.#.#.#.#.###.#.#####.#####.#.#####.#.#.#.#.#.#####.#.#.#.#####.#.#.#.#.#.#.#.#.#.#.#.#.#.#####.###.#########.#.#.#.#.#.#.#.#.#.#.# +#...#.....#.#.#.#.#...#...#.....#...#.#...#...#.#.#.#.#.....#.#.#.#.....#.#...#.#.#.#.#.#.#.#.#.#.#...#...###...#...#...#.#.#.#.#.#.#...#...# +#####.#####.#.#.#.###.#####.#####.#.#.###.#.###.#.#.#.#####.#.#.#.#####.#.#####.#.#.#.#.#.#.#.#.#.###.#.#######.#.#.#.###.#.#.#.#.#.######### +#.....#.....#.#.#...#.#.....#...#.#.#.#...#.###.#.#.#.....#.#.#.#...#...#.....#.#.#.#.#.#.#...#.#.#...#.......#.#.#.#.#...#.#.#.#.#.......### +#.#####.#####.#.###.#.#.#####.#.#.#.#.#.###.###.#.#.#####.#.#.#.###.#.#######.#.#.#.#.#.#.#####.#.#.#########.#.#.#.#.#.###.#.#.#.#######.### +#.#...#.#.....#...#...#.....#.#...#...#...#...#.#.#...#...#.#.#.....#...#.....#.#.#...#.#.#.....#.#.#...#.....#.#.#.#.#.#...#...#.......#...# +#.#.#.#.#.#######.#########.#.###########.###.#.#.###.#.###.#.#########.#.#####.#.#####.#.#.#####.#.#.#.#.#####.#.#.#.#.#.#############.###.# +#.#.#.#.#...#...#.#.........#...#.......#.#...#.#...#.#...#.#.###.......#.....#.#.....#.#.#.#...#.#...#.#.....#...#.#.#.#.###.........#...#.# +#.#.#.#.###.#.#.#.#.###########.#.#####.#.#.###.###.#.###.#.#.###.###########.#.#####.#.#.#.#.#.#.#####.#####.#####.#.#.#.###.#######.###.#.# +#.#.#.#.#...#.#...#...#.....#...#.#...#...#...#.#...#.#...#.#.#...#.......#...#...#...#.#.#...#.#...#...#...#...###...#.#.....#.....#...#.#.# +#.#.#.#.#.###.#######.#.###.#.###.#.#.#######.#.#.###.#.###.#.#.###.#####.#.#####.#.###.#.#####.###.#.###.#.###.#######.#######.###.###.#.#.# +#.#.#.#.#...#.###...#.#.#...#.###...#...#.....#...#...#...#...#...#.....#.#.#...#.#.#...#.#.....#...#...#.#.....#.....#.#.......###.....#.#.# +#.#.#.#.###.#.###.#.#.#.#.###.#########.#.#########.#####.#######.#####.#.#.#.#.#.#.#.###.#.#####.#####.#.#######.###.#.#.###############.#.# +#...#.#.#...#.#...#...#.#...#...###.....#.........#...#...#.......#.....#.#...#.#...#...#.#.#...#.....#.#.........#...#.#.........###...#...# +#####.#.#.###.#.#######.###.###.###.#############.###.#.###.#######.#####.#####.#######.#.#.#.#.#####.#.###########.###.#########.###.#.##### +#.....#.#...#.#...#...#.#...#...#...#.....#...#...###...###.....#...###...#...#.......#...#...#...#...#.#...#...#...#...#...#...#.....#.....# +#.#####.###.#.###.#.#.#.#.###.###.###.###.#.#.#.###############.#.#####.###.#.#######.###########.#.###.#.#.#.#.#.###.###.#.#.#.###########.# +#.......###...###.#.#.#.#.....#...#...#...#.#...###.............#.....#...#.#.#...#...#...........#.###...#.#.#.#.###.....#...#.....#.......# +#################.#.#.#.#######.###.###.###.#######.#################.###.#.#.#.#.#.###.###########.#######.#.#.#.#################.#.####### +###...............#.#.#.#.......#...###...#.......#.......#.....#.....###.#.#.#.#...###.....#.....#.......#.#.#.#.......#...#...#...#.......# +###.###############.#.#.#.#######.#######.#######.#######.#.###.#.#######.#.#.#.###########.#.###.#######.#.#.#.#######.#.#.#.#.#.#########.# +#...#...#...#...#...#.#.#.....#...#...###.#.......#.......#.#...#.......#...#.#...........#...###.#...#...#.#.#.#.....#...#...#.#.#...#...#.# +#.###.#.#.#.#.#.#.###.#.#####.#.###.#.###.#.#######.#######.#.#########.#####.###########.#######.#.#.#.###.#.#.#.###.#########.#.#.#.#.#.#.# +#.....#.#.#...#...###.#.#.....#.....#.#...#.....###.#.....#.#...#...#...#.....#...#.....#.###.....#.#...#...#.#.#...#.#...#...#.#.#.#.#.#.#.# +#######.#.###########.#.#.###########.#.#######.###.#.###.#.###.#.#.#.###.#####.#.#.###.#.###.#####.#####.###.#.###.#.#.#.#.#.#.#.#.#.#.#.#.# +###.....#.#...........#.#...#...#...#.#.#.....#...#.#.###.#.#...#.#...###...#...#.#.###...#...#...#...###.....#.#...#.#.#...#...#...#...#.#.# +###.#####.#.###########.###.#.#.#.#.#.#.#.###.###.#.#.###.#.#.###.#########.#.###.#.#######.###.#.###.#########.#.###.#.#################.#.# +#...#.....#...#.......#...#...#.#.#...#.#...#.#...#.#.#...#.#...#.........#.#...#.#.......#...#.#...#.........#...###.#.#...#...........#...# +#.###.#######.#.#####.###.#####.#.#####.###.#.#.###.#.#.###.###.#########.#.###.#.#######.###.#.###.#########.#######.#.#.#.#.#########.##### +#...#.#.......#.....#...#.#.....#.#.....#...#.#.###.#.#...#.###.#...#...#.#.#...#...#.....###.#.#...#...#...#.......#.#...#...#...#...#.....# +###.#.#.###########.###.#.#.#####.#.#####.###.#.###.#.###.#.###.#.#.#.#.#.#.#.#####.#.#######.#.#.###.#.#.#.#######.#.#########.#.#.#.#####.# +###.#.#.#.....#...#.###...#...#...#.#...#...#.#...#...###...#...#.#.#.#.#.#.#.#...#.#.......#...#...#.#...#...#.....#...#...#...#...#.#.....# +###.#.#.#.###.#.#.#.#########.#.###.#.#.###.#.###.###########.###.#.#.#.#.#.#.#.#.#.#######.#######.#.#######.#.#######.#.#.#.#######.#.##### +#...#.#.#.#...#.#.#.#.........#.#...#.#...#.#...#.....#.......#...#.#.#.#.#.#.#.#...#...#...#.......#.......#.#.......#.#.#.#.....#...#.....# +#.###.#.#.#.###.#.#.#.#########.#.###.###.#.###.#####.#.#######.###.#.#.#.#.#.#.#####.#.#.###.#############.#.#######.#.#.#.#####.#.#######.# +#.....#...#.....#...#...........#.....###...###.......#.........###...#...#...#.......#...###...............#.........#...#.......#.........# +############################################################################################################################################# \ No newline at end of file diff --git a/src/test/kotlin/adventofcode/common/spatial/Point2dSpec.kt b/src/test/kotlin/adventofcode/common/spatial/Point2dSpec.kt index 4152f17..220fe67 100644 --- a/src/test/kotlin/adventofcode/common/spatial/Point2dSpec.kt +++ b/src/test/kotlin/adventofcode/common/spatial/Point2dSpec.kt @@ -11,15 +11,17 @@ class Point2dSpec : FreeSpec({ } } - "plus Point2d operator" - { - "adds two Point2ds correctly together by adding each of their coordinates together" { - Point2d(1024, 2048) + Point2d(1024, 2048) shouldBe Point2d(2048, 4096) + "operator plus" - { + "other Point2d" - { + "adds two Point2ds correctly together by adding each of their coordinates together" { + Point2d(1024, 2048) + Point2d(1024, 2048) shouldBe Point2d(2048, 4096) + } } - } - "plus Number operator" - { - "shifts both coordinates of the point by the offset provided" { - Point2d(1, 2) + 3 shouldBe Point2d(4, 5) + "constant Number offset" - { + "shifts both coordinates of the point by the offset provided" { + Point2d(1, 2) + 3 shouldBe Point2d(4, 5) + } } } @@ -52,4 +54,14 @@ class Point2dSpec : FreeSpec({ } } } + + "distanceTo" - { + "returns the Manhattan distance between two points" { + Point2d(1, 1) distanceTo Point2d(2, 3) shouldBe 3 + } + + "returns the Manhattan distance between two points with negative coordinates" { + Point2d(-2, -3) distanceTo Point2d(4, 5) shouldBe 14 + } + } }) diff --git a/src/test/kotlin/adventofcode/year2024/Day20RaceConditionSpec.kt b/src/test/kotlin/adventofcode/year2024/Day20RaceConditionSpec.kt new file mode 100644 index 0000000..eb86729 --- /dev/null +++ b/src/test/kotlin/adventofcode/year2024/Day20RaceConditionSpec.kt @@ -0,0 +1,7 @@ +package adventofcode.year2024 + +import adventofcode.PuzzleBaseSpec + +// The example uses a different minimum savings goal than the actual input, +// so this test runs the code on my actual input. +class Day20RaceConditionSpec : PuzzleBaseSpec(1426)