Skip to content

Commit

Permalink
2024 - Day 25 - part 1 - no part 2 as usual...
Browse files Browse the repository at this point in the history
  • Loading branch information
fmmr committed Dec 25, 2024
1 parent de70581 commit 962d3f2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
40 changes: 25 additions & 15 deletions src/main/kotlin/no/rodland/advent_2024/Day25.kt
Original file line number Diff line number Diff line change
@@ -1,35 +1,45 @@
package no.rodland.advent_2024

import no.rodland.advent.Day
import no.rodland.advent.toCave

// template generated: 25/12/2024
// Fredrik Rødland 2024

class Day25(val input: List<String>) : Day<Long, Long, List<String>> {
class Day25(val input: List<String>) : Day<Int, Long, Pair<List<String>, List<String>>> {

private val parsed = input.parse()
private val locks = parsed.first.map { it.split("\n").toCave() }
private val keys = parsed.second.map { it.split("\n").toCave() }
val x = 0..4
val y = 0..6

override fun partOne(): Int {
val free = locks.map { lock ->
x.map { x ->
y.count { y -> lock[y][x] == '.' }
}
}
val used = keys.map { lock ->
x.map { x ->
y.count { y -> lock[y][x] == '#' } - 1
}
}

override fun partOne(): Long {
return 2
return used.sumOf { key ->
free.count { lock ->
key.zip(lock).all { it.second - it.first > 0 }
}
}
}

override fun partTwo(): Long {
return 2
}

override fun List<String>.parse(): List<String> {

override fun List<String>.parse(): Pair<List<String>, List<String>> {
val (locks, keys) = joinToString("\n").split("\n\n").partition { it.startsWith("#####") }
return map { line ->
line
}
}
sealed interface Thing
data class Lock(val init: String): Thing {

}
data class Key(val init: String): Thing {

return locks to keys
}

override val day = "25".toInt()
Expand Down
5 changes: 3 additions & 2 deletions src/test/kotlin/no/rodland/advent_2024/Day25Test.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ internal class Day25Test {
private val data25 = "2024/input_25.txt".readFile()
private val test25 = "2024/input_25_test.txt".readFile()

private val resultTestOne = 2L
private val resultTestOne = 3
private val resultTestTwo = 2L
private val resultOne = 2L
private val resultOne = 3249
private val resultTwo = 2L

val test = defaultTestSuiteParseOnInit(
Expand All @@ -29,6 +29,7 @@ internal class Day25Test {
resultTwo,
{ Day25(data25) },
{ Day25(test25) },
numTestPart1 = 20
)

@Nested
Expand Down

0 comments on commit 962d3f2

Please sign in to comment.