Skip to content

Commit c87e403

Browse files
committed
day20: removed unnecessary parallelization
1 parent 67e1e67 commit c87e403

File tree

1 file changed

+7
-21
lines changed

1 file changed

+7
-21
lines changed

day20/main.go

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"flag"
66
"fmt"
77
"os"
8-
"sync"
98

109
"github.com/fxnn/adventofcode2024/util"
1110
)
@@ -156,27 +155,14 @@ func main() {
156155
var time = len(moves) - 1
157156
fmt.Printf("course takes %d picoseconds\n", time)
158157

159-
var cheatChan = make(chan cheat)
160-
var inProgressMoves sync.WaitGroup
161-
for i := range moves {
162-
inProgressMoves.Add(1)
163-
go func(startIdx int) {
164-
defer inProgressMoves.Done()
165-
for _, c := range findCheats(course, moves, startIdx, *minSaving, *debug) {
166-
cheatChan <- c
167-
}
168-
fmt.Printf("searched cheats for %d/%d moves\n", startIdx+1, len(moves))
169-
}(i)
170-
}
171-
172-
go func() {
173-
inProgressMoves.Wait()
174-
close(cheatChan)
175-
}()
176-
177158
var cheats = make(map[cheat]util.Void)
178-
for c := range cheatChan {
179-
cheats[c] = util.Void{}
159+
for startIdx := range moves {
160+
for _, c := range findCheats(course, moves, startIdx, *minSaving, *debug) {
161+
cheats[c] = util.Void{}
162+
}
163+
if startIdx%100 == 0 {
164+
fmt.Printf("searched cheats for %d/%d moves\n", startIdx+1, len(moves))
165+
}
180166
}
181167

182168
fmt.Printf("found %d unique cheats saving >= %d picoseconds", len(cheats), *minSaving)

0 commit comments

Comments
 (0)