Skip to content

Commit

Permalink
day20: removed unnecessary parallelization
Browse files Browse the repository at this point in the history
  • Loading branch information
fxnn committed Dec 22, 2024
1 parent 67e1e67 commit c87e403
Showing 1 changed file with 7 additions and 21 deletions.
28 changes: 7 additions & 21 deletions day20/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"flag"
"fmt"
"os"
"sync"

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

var cheatChan = make(chan cheat)
var inProgressMoves sync.WaitGroup
for i := range moves {
inProgressMoves.Add(1)
go func(startIdx int) {
defer inProgressMoves.Done()
for _, c := range findCheats(course, moves, startIdx, *minSaving, *debug) {
cheatChan <- c
}
fmt.Printf("searched cheats for %d/%d moves\n", startIdx+1, len(moves))
}(i)
}

go func() {
inProgressMoves.Wait()
close(cheatChan)
}()

var cheats = make(map[cheat]util.Void)
for c := range cheatChan {
cheats[c] = util.Void{}
for startIdx := range moves {
for _, c := range findCheats(course, moves, startIdx, *minSaving, *debug) {
cheats[c] = util.Void{}
}
if startIdx%100 == 0 {
fmt.Printf("searched cheats for %d/%d moves\n", startIdx+1, len(moves))
}
}

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

0 comments on commit c87e403

Please sign in to comment.