File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed
year2024/src/main/kotlin/net/olegg/aoc/year2024/day20 Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -12,9 +12,15 @@ import net.olegg.aoc.year2024.DayOf2024
12
12
* See [Year 2024, Day 20](https://adventofcode.com/2024/day/20)
13
13
*/
14
14
object Day20 : DayOf2024(20 ) {
15
- private val cheats = NEXT_4 .map { it.step * 2 }
16
-
17
15
override fun first (): Any? {
16
+ return solve(2 )
17
+ }
18
+
19
+ override fun second (): Any? {
20
+ return solve(20 )
21
+ }
22
+
23
+ private fun solve (maxCheat : Int , minSave : Int = 100): Int {
18
24
val start = matrix.find(' S' )!!
19
25
val end = matrix.find(' E' )!!
20
26
@@ -48,7 +54,9 @@ object Day20 : DayOf2024(20) {
48
54
val (firstPos, firstStep) = first
49
55
val (secondPos, secondStep) = second
50
56
51
- secondStep - firstStep - 2 >= 100 && (secondPos - firstPos) in cheats
57
+ val delta = (secondPos - firstPos).manhattan()
58
+
59
+ delta <= maxCheat && secondStep - firstStep - delta >= minSave
52
60
}
53
61
}
54
62
}
You can’t perform that action at this time.
0 commit comments