Skip to content

Commit

Permalink
Day 25: Code Chronicle
Browse files Browse the repository at this point in the history
  • Loading branch information
andilau committed Dec 25, 2024
1 parent 8a0fc9a commit 9a0bc18
Show file tree
Hide file tree
Showing 5 changed files with 4,101 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Advent of Code is an Advent calendar of small programming puzzles by [Eric Wastl
- Day 14: [Restroom Redoubt](https://adventofcode.com/2024/day/14) -- [Day14.kt](https://github.com/andilau/advent-of-code-2024/blob/main/src/main/kotlin/days/Day14.kt)
- Day 18: [RAM Run](https://adventofcode.com/2024/day/18) -- [Day18.kt](https://github.com/andilau/advent-of-code-2024/blob/main/src/main/kotlin/days/Day18.kt)
- Day 22: [Monkey Market](https://adventofcode.com/2024/day/22) -- [Day22.kt](https://github.com/andilau/advent-of-code-2024/blob/main/src/main/kotlin/days/Day22.kt)
- Day 25: [Day 25: Code Chronicle](https://adventofcode.com/2024/day/25) -- [Day25.kt](https://github.com/andilau/advent-of-code-2024/blob/main/src/main/kotlin/days/Day25.kt)

### Features

Expand Down
37 changes: 37 additions & 0 deletions src/main/kotlin/days/Day25.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package days

@AdventOfCodePuzzle(
name = "Code Chronicle",
url = "https://adventofcode.com/2024/day/25",
date = Date(day = 25, year = 2024)
)
class Day25(val input: String) : Puzzle {
private val securities: List<Security> = input.split("\n\n").map { Security.from(it) }

override fun partOne(): Int = securities
.filterIsInstance<Security.Lock>()
.flatMap { key -> securities.filterIsInstance<Security.Key>().map { lock -> key to lock } }
.count { (lock, key) -> lock.signature.zip(key.signatur).all { (l, p) -> l + p <= 5 } }

override fun partTwo() = Unit

sealed class Security() {
data class Lock(val signature: List<Int>) : Security()
data class Key(val signatur: List<Int>) : Security()

companion object {
fun from(input: String): Security {
val lines = input.lines()
return when {
lines.first().all { it == '#' } -> Lock(pivot(lines.drop(1)).map { it.count { it == '#' } })
lines.last().all { it == '#' } -> Key(pivot(lines.dropLast(1)).map { it.count { it == '#' } })
else -> error("Something else")
}
}

private fun pivot(list: List<String>): List<String> {
return list[0].indices.map { col -> list.map { it[col] }.joinToString("") }
}
}
}
}
Loading

0 comments on commit 9a0bc18

Please sign in to comment.