-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
4,140 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/main/kotlin/adventofcode/year2024/Day25CodeChronicle.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Char>.toHeights(): List<Int> = columns().map { column -> column.count { it == FILLED } } | ||
} | ||
} |
Oops, something went wrong.