generated from kotlin-hands-on/advent-of-code-kotlin-template
-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
fa3a233
commit 1f89003
Showing
2 changed files
with
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package aoc.year2024 | ||
|
||
import aoc.library.Puzzle | ||
|
||
object Day25 : Puzzle<Int, Unit>(day = 25) { | ||
|
||
override fun solvePart1(input: String): Int { | ||
val (keys, locks) = parse(input) | ||
return keys.sumOf { key -> | ||
locks.count { lock -> | ||
keyMatchesLock(key, lock) | ||
} | ||
} | ||
} | ||
|
||
private fun keyMatchesLock( | ||
key: List<Int>, | ||
lock: List<Int>, | ||
): Boolean = key.zip(lock).all { (k, l) -> | ||
k + l <= 5 | ||
} | ||
|
||
private fun parse(input: String): Pair<List<List<Int>>, List<List<Int>>> { | ||
val keys = mutableListOf<List<Int>>() | ||
val locks = mutableListOf<List<Int>>() | ||
input.split("\n\n").map { | ||
val lines = it.lines() | ||
val isKey = lines[0][0] == '#' | ||
val pins = List(5) { row -> | ||
(1..5).count { column -> | ||
lines[column][row] == '#' | ||
} | ||
} | ||
if (isKey) keys += pins else locks += pins | ||
} | ||
return keys to locks | ||
} | ||
|
||
override fun solvePart2(input: String) { | ||
} | ||
} |
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,60 @@ | ||
package aoc.year2024 | ||
|
||
import aoc.library.solvePart1 | ||
import io.kotest.matchers.ints.shouldBeExactly | ||
import org.junit.jupiter.api.Test | ||
|
||
class Day25Test { | ||
|
||
@Test | ||
fun part1TestInput() { | ||
Day25.solvePart1( | ||
""" | ||
##### | ||
.#### | ||
.#### | ||
.#### | ||
.#.#. | ||
.#... | ||
..... | ||
##### | ||
##.## | ||
.#.## | ||
...## | ||
...#. | ||
...#. | ||
..... | ||
..... | ||
#.... | ||
#.... | ||
#...# | ||
#.#.# | ||
#.### | ||
##### | ||
..... | ||
..... | ||
#.#.. | ||
###.. | ||
###.# | ||
###.# | ||
##### | ||
..... | ||
..... | ||
..... | ||
#.... | ||
#.#.. | ||
#.#.# | ||
##### | ||
""".trimIndent(), | ||
) shouldBeExactly 3 | ||
} | ||
|
||
@Test | ||
fun part1() { | ||
Day25.solvePart1() shouldBeExactly 3360 | ||
} | ||
} |