Skip to content

Commit

Permalink
Christmas
Browse files Browse the repository at this point in the history
  • Loading branch information
hibob224 committed Dec 25, 2024
1 parent aff0e71 commit 46a9d33
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/main/kotlin/y2024/day25/Day25.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package y2024.day25

import utils.getInputFile
import utils.toPointGrid

fun main() {
println("Part one: " + Day25().solvePartOne())
}

class Day25 {

private val locks: List<Map<Int, Int>>
private val keys: List<Map<Int, Int>>

init {
val (lockIn, keyIn) = getInputFile(example = false)
.readText()
.split("\n\n")
.partition { it.first() == '#' }
locks = lockIn.map { it.lines().toPointGrid().filterValues { it == '#' }.keys.groupingBy { it.x }.eachCount() }
keys = keyIn.map { it.lines().toPointGrid().filterValues { it == '#' }.keys.groupingBy { it.x }.eachCount() }
}

fun solvePartOne(): Int {
return locks.sumOf { lock ->
keys.count { key ->
lock.entries.all { (x, c) ->
key.getValue(x) + c <= 7
}
}
}
}
}
Binary file added src/main/kotlin/y2024/day25/input.txt
Binary file not shown.
13 changes: 13 additions & 0 deletions src/test/kotlin/y2024/day25/Day25Test.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package y2024.day25

import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

internal class Day25Test {


@Test
fun solvePartOne() {
assertEquals(3114, Day25().solvePartOne())
}
}

0 comments on commit 46a9d33

Please sign in to comment.