Skip to content

Commit

Permalink
AoC 2024 Day 14 Part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
GeistInDerSH committed Dec 14, 2024
1 parent fae4772 commit c01a534
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
20 changes: 17 additions & 3 deletions src/main/kotlin/com/geistindersh/aoc/year2024/Day14.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class Day14(
else -> 3
}

fun next() = next(1)

fun next(steps: Int) =
this.copy(
position =
Expand All @@ -46,19 +48,31 @@ class Day14(
}
}

private fun robotsWithBounds(
height: Int,
width: Int,
) = robots.map { it.copy(height = height, width = width) }

fun part1(
height: Int,
width: Int,
) = robots
.mapNotNull { it.copy(height = height, width = width).next(100).quadrant() }
) = robotsWithBounds(height, width)
.mapNotNull { it.next(100).quadrant() }
.groupingBy { it }
.eachCount()
.values
.reduce(Int::times)

fun part1() = part1(height = 103, width = 101)

fun part2() = 0
fun part2(
height: Int,
width: Int,
) = generateSequence(0 to robotsWithBounds(height, width)) { (round, bots) -> round + 1 to bots.map { it.next() } }
.first { (_, bots) -> bots.map { it.position }.toSet().size == robots.size }
.first

fun part2() = part2(height = 103, width = 101)
}

fun day14() {
Expand Down
3 changes: 1 addition & 2 deletions src/test/kotlin/com/geistindersh/aoc/year2024/Day14Test.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class Day14Test {

@Test
fun part2() {
assertEquals(-1, Day14(DataFile.Example).part2())
assertEquals(-1, Day14(DataFile.Part1).part2())
assertEquals(0, 0)
}
}

0 comments on commit c01a534

Please sign in to comment.