From c87e4038aaf59b84d1e4a05a37593befb1944abd Mon Sep 17 00:00:00 2001 From: Felix Neumann Date: Mon, 23 Dec 2024 00:06:10 +0100 Subject: [PATCH] day20: removed unnecessary parallelization --- day20/main.go | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/day20/main.go b/day20/main.go index 7473031..dcb7b8b 100644 --- a/day20/main.go +++ b/day20/main.go @@ -5,7 +5,6 @@ import ( "flag" "fmt" "os" - "sync" "github.com/fxnn/adventofcode2024/util" ) @@ -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)