Skip to content

Commit

Permalink
2024 - Day 14 - part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
fmmr committed Dec 14, 2024
1 parent 6b571c5 commit 459762d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
14 changes: 10 additions & 4 deletions src/main/kotlin/no/rodland/advent_2024/Day14.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,28 @@ import product
// template generated: 14/12/2024
// Fredrik Rødland 2024

class Day14(val input: List<String>, val width: Int, val height: Int) : Day<Long, Long, List<Day14.Robot>> {
class Day14(val input: List<String>, val width: Int, val height: Int) : Day<Long, Int, List<Day14.Robot>> {

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) {
Expand Down
9 changes: 3 additions & 6 deletions src/test/kotlin/no/rodland/advent_2024/Day14Test.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -33,6 +29,7 @@ internal class Day14Test {
resultTwo,
{ Day14(data14, 101, 103) },
{ Day14(test14, 11, 7) },
numTestPart2 = 1
)

@Nested
Expand Down

0 comments on commit 459762d

Please sign in to comment.