Skip to content

Commit

Permalink
Solve Day 25
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulWoitaschek committed Dec 25, 2024
1 parent fa3a233 commit 1f89003
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 0 deletions.
41 changes: 41 additions & 0 deletions 2024/src/main/kotlin/aoc/year2024/Day25.kt
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) {
}
}
60 changes: 60 additions & 0 deletions 2024/src/test/kotlin/aoc/year2024/Day25Test.kt
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
}
}

0 comments on commit 1f89003

Please sign in to comment.