diff --git a/src/main/kotlin/no/rodland/advent_2024/Day14.kt b/src/main/kotlin/no/rodland/advent_2024/Day14.kt index 5e3c356e..a11fb489 100644 --- a/src/main/kotlin/no/rodland/advent_2024/Day14.kt +++ b/src/main/kotlin/no/rodland/advent_2024/Day14.kt @@ -7,22 +7,28 @@ import product // template generated: 14/12/2024 // Fredrik Rødland 2024 -class Day14(val input: List, val width: Int, val height: Int) : Day> { +class Day14(val input: List, val width: Int, val height: Int) : Day> { private val robots = input.parse() override fun partOne(): Long { return robots.map { it.move(100, width, height) } .groupBy { it.quadrant(width, height) } - .toSortedMap() .filterKeys { i: Int -> i != 0 } // middle .values .map { it.size } .product() } - override fun partTwo(): Long { - return 2 + override fun partTwo(): Int { + // no overlaps? + val hei = (0..width * height).map { i -> + val overlaps = robots.map { it.move(i, width, height) } + .groupBy { it } + .count { (_, v) -> v.size > 1 } + i to overlaps + }.first { it.second == 0 } + return hei.first } data class Robot(val pos: Pos, val vel: Pos) { diff --git a/src/test/kotlin/no/rodland/advent_2024/Day14Test.kt b/src/test/kotlin/no/rodland/advent_2024/Day14Test.kt index fe1fe49b..b9be60b1 100644 --- a/src/test/kotlin/no/rodland/advent_2024/Day14Test.kt +++ b/src/test/kotlin/no/rodland/advent_2024/Day14Test.kt @@ -16,13 +16,9 @@ internal class Day14Test { private val test14 = "2024/input_14_test.txt".readFile() private val resultTestOne = 12L - private val resultTestTwo = 2L + private val resultTestTwo = 1 private val resultOne = 221142636L - private val resultTwo = 2L -// private val width = 101 -// private val height = 103 -// private val widthExample = 11 -// private val heightExample = 7 + private val resultTwo = 7916 val test = defaultTestSuiteParseOnInit( Day14(data14, 101, 103), @@ -33,6 +29,7 @@ internal class Day14Test { resultTwo, { Day14(data14, 101, 103) }, { Day14(test14, 11, 7) }, + numTestPart2 = 1 ) @Nested