File tree Expand file tree Collapse file tree 2 files changed +4
-6
lines changed
main/scala/eu/sim642/adventofcode2024
test/scala/eu/sim642/adventofcode2024 Expand file tree Collapse file tree 2 files changed +4
-6
lines changed Original file line number Diff line number Diff line change @@ -28,17 +28,15 @@ object Day20 {
28
28
trait Part {
29
29
val maxCheat : Int
30
30
31
- def findCheats (grid : Grid [Char ]): Set [Cheat ] = {
31
+ def findCheats (grid : Grid [Char ]): Iterable [Cheat ] = {
32
32
val forwardSearch = gridGraphSearch(grid, 'S' , 'E' )
33
33
val forwardResult = BFS .search(forwardSearch)
34
34
val backwardSearch = gridGraphSearch(grid, 'E' , 'S' )
35
35
val backwardResult = BFS .search(backwardSearch)
36
36
37
37
val noCheatDistance = forwardResult.target.get._2
38
38
39
- // TODO: optimize
40
-
41
- (for {
39
+ for {
42
40
(row, y) <- grid.view.zipWithIndex
43
41
(cell, x) <- row.view.zipWithIndex
44
42
if cell != '#'
@@ -55,7 +53,7 @@ object Day20 {
55
53
cheatDistance = forwardResult.distances(start) + (startCheat + endCheat) + backwardResult.distances(end)
56
54
// if cheatDistance <= noCheatDistance
57
55
save = noCheatDistance - cheatDistance
58
- } yield Cheat (start, end, save)).toSet
56
+ } yield Cheat (start, end, save)
59
57
}
60
58
61
59
def countGoodCheats (grid : Grid [Char ]): Int = findCheats(grid).count(_.save >= 100 )
Original file line number Diff line number Diff line change @@ -60,7 +60,7 @@ class Day20Test extends AnyFunSuite {
60
60
assert(cheats(76 ) == 3 )
61
61
}
62
62
63
- test(" Part 2 input answer" ) { // TODO: optimize (~4.3s)
63
+ test(" Part 2 input answer" ) {
64
64
assert(Part2 .countGoodCheats(parseGrid(input)) == 1011325 )
65
65
}
66
66
}
You can’t perform that action at this time.
0 commit comments