Skip to content

Commit 98f0e3a

Browse files
committed
Make Day20's implementation a class, express the small examples as tests
Coverage: - class: 78% - method: 83% - line: 83% - branch: 85%
1 parent 9188dbe commit 98f0e3a

File tree

2 files changed

+43
-29
lines changed

2 files changed

+43
-29
lines changed

src/main/kotlin/de/ronny_h/aoc/year24/day20/Day20.kt renamed to src/main/kotlin/de/ronny_h/aoc/year24/day20/RaceCondition.kt

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,17 @@ import readInput
1010

1111
fun main() {
1212
val day = "Day20"
13+
val input = readInput(day)
14+
val raceCondition = RaceCondition()
15+
16+
println("$day part 1")
17+
printAndCheck(input, raceCondition::part1Large, 1438)
1318

19+
println("$day part 2")
20+
printAndCheck(input, raceCondition::part2Large, 1026446)
21+
}
22+
23+
class RaceCondition {
1424
fun part1(input: List<String>, minPicosecondsSaved: Int, shortcutMaxLength: Int): Int {
1525
val track = RaceTrack(input)
1626
track.printGrid()
@@ -23,35 +33,6 @@ fun main() {
2333
fun part2Small(input: List<String>) = part1(input, 76, 20)
2434
fun part2Large(input: List<String>) = part1(input, 100, 20)
2535

26-
println("$day part 1")
27-
28-
val testInput = """
29-
###############
30-
#...#...#.....#
31-
#.#.#.#.#.###.#
32-
#S#...#.#.#...#
33-
#######.#.#.###
34-
#######.#.#...#
35-
#######.#.###.#
36-
###..E#...#...#
37-
###.#######.###
38-
#...###...#...#
39-
#.#####.#.###.#
40-
#.#...#.#.#...#
41-
#.#.#.#.#.#.###
42-
#...#...#...###
43-
###############
44-
""".trimIndent().split('\n')
45-
printAndCheck(testInput, ::part1Small, 10)
46-
47-
val input = readInput(day)
48-
printAndCheck(input, ::part1Large, 1438)
49-
50-
51-
println("$day part 2")
52-
53-
printAndCheck(testInput, ::part2Small, 3)
54-
printAndCheck(input, ::part2Large, 1026446)
5536
}
5637

5738
private class RaceTrack(input: List<String>) : Grid<Char>(input, '#') {
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package de.ronny_h.aoc.year24.day20
2+
3+
import de.ronny_h.aoc.extensions.asList
4+
import io.kotest.core.spec.style.StringSpec
5+
import io.kotest.matchers.shouldBe
6+
7+
class RaceConditionTest : StringSpec({
8+
val input = """
9+
###############
10+
#...#...#.....#
11+
#.#.#.#.#.###.#
12+
#S#...#.#.#...#
13+
#######.#.#.###
14+
#######.#.#...#
15+
#######.#.###.#
16+
###..E#...#...#
17+
###.#######.###
18+
#...###...#...#
19+
#.#####.#.###.#
20+
#.#...#.#.#...#
21+
#.#.#.#.#.#.###
22+
#...#...#...###
23+
###############
24+
""".asList()
25+
26+
"part 1: Number of 2ps cheats saving at least 10 picoseconds" {
27+
RaceCondition().part1Small(input) shouldBe 10
28+
}
29+
30+
"part 2: Number of 20ps cheats saving at least 76 picoseconds" {
31+
RaceCondition().part2Small(input) shouldBe 3
32+
}
33+
})

0 commit comments

Comments
 (0)