Skip to content

Commit a328c49

Browse files
committed
solve 20th day 2nd task
1 parent 1965c7e commit a328c49

File tree

1 file changed

+11
-3
lines changed
  • year2024/src/main/kotlin/net/olegg/aoc/year2024/day20

1 file changed

+11
-3
lines changed

year2024/src/main/kotlin/net/olegg/aoc/year2024/day20/Day20.kt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,15 @@ import net.olegg.aoc.year2024.DayOf2024
1212
* See [Year 2024, Day 20](https://adventofcode.com/2024/day/20)
1313
*/
1414
object Day20 : DayOf2024(20) {
15-
private val cheats = NEXT_4.map { it.step * 2 }
16-
1715
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 {
1824
val start = matrix.find('S')!!
1925
val end = matrix.find('E')!!
2026

@@ -48,7 +54,9 @@ object Day20 : DayOf2024(20) {
4854
val (firstPos, firstStep) = first
4955
val (secondPos, secondStep) = second
5056

51-
secondStep - firstStep - 2 >= 100 && (secondPos - firstPos) in cheats
57+
val delta = (secondPos - firstPos).manhattan()
58+
59+
delta <= maxCheat && secondStep - firstStep - delta >= minSave
5260
}
5361
}
5462
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy