Skip to content

Commit

Permalink
Day 25: Code Chronicle (#22)
Browse files Browse the repository at this point in the history
* Day 25: Code Chronicle

* Day 25: Code Chronicle
  • Loading branch information
andilau authored Dec 25, 2024
1 parent 0a98571 commit f52c952
Show file tree
Hide file tree
Showing 5 changed files with 4,100 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Advent of Code is an Advent calendar of small programming puzzles by [Eric Wastl
- 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 23: [LAN Party](https://adventofcode.com/2024/day/23) -- [Day23.kt](https://github.com/andilau/advent-of-code-2024/blob/main/src/main/kotlin/days/Day23.kt) 1/2
- 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 f52c952

Please sign in to comment.