Skip to content

Commit 5ffc6e6

Browse files
committed
2025, Day 7
1 parent e92f34a commit 5ffc6e6

File tree

4 files changed

+90
-0
lines changed

4 files changed

+90
-0
lines changed

.idea/runConfigurations/2025__Day_7.xml

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package lv.esupe.aoc.year2025
2+
3+
import lv.esupe.aoc.Puzzle
4+
import lv.esupe.aoc.model.Grid
5+
import lv.esupe.aoc.model.Point
6+
import lv.esupe.aoc.solve
7+
import lv.esupe.aoc.utils.memoize
8+
9+
fun main() = solve { Day7() }
10+
11+
class Day7 : Puzzle<Int, Long>(2025, 7) {
12+
override val input = Grid.from(rawInput)
13+
private val start = input.firstNotNullOf { it.takeIf { it.value == 'S' } }
14+
private val numTimelines = memoize(::_numTimelines)
15+
16+
override fun solvePartOne(): Int {
17+
val queue = mutableSetOf(start.key)
18+
var splits = 0
19+
while (queue.isNotEmpty()) {
20+
val p = queue.first()
21+
queue.remove(p)
22+
val newP = p.up()
23+
if (input[newP] == '^') {
24+
queue.add(newP.left())
25+
queue.add(newP.right())
26+
splits++
27+
} else if (input.isInBounds(newP)) {
28+
queue.add(newP)
29+
}
30+
}
31+
return splits
32+
}
33+
34+
override fun solvePartTwo(): Long {
35+
return numTimelines(start.key)
36+
}
37+
38+
private fun _numTimelines(from: Point): Long {
39+
val newP = from.up()
40+
return when {
41+
input[newP] == '^' -> numTimelines(newP.left()) + numTimelines(newP.right())
42+
input.isInBounds(newP) -> numTimelines(newP)
43+
else -> 1L
44+
}
45+
}
46+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package lv.esupe.aoc.year2025
2+
3+
import lv.esupe.aoc.DayTest
4+
import org.junit.jupiter.api.Test
5+
6+
class Day7Test : DayTest<Int, Long>() {
7+
override val puzzle = { Day7() }
8+
9+
@Test
10+
fun day7_1() {
11+
runTest("_1", 21, 40)
12+
}
13+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.......S.......
2+
...............
3+
.......^.......
4+
...............
5+
......^.^......
6+
...............
7+
.....^.^.^.....
8+
...............
9+
....^.^...^....
10+
...............
11+
...^.^...^.^...
12+
...............
13+
..^...^.....^..
14+
...............
15+
.^.^.^.^.^...^.
16+
...............

0 commit comments

Comments
 (0)