generated from andilau/advent-of-code-starter
-
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
5 changed files
with
4,101 additions
and
0 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
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("") } | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.