File tree 2 files changed +24
-9
lines changed
2 files changed +24
-9
lines changed Original file line number Diff line number Diff line change @@ -60,7 +60,7 @@ Using Go's built-in benchmarking with the [testing](https://pkg.go.dev/testing#h
60
60
| 17 | 13964 ns/op | 561424 ns/op | |
61
61
| 18 | 755414 ns/op | 1996995 ns/op | |
62
62
| 19 | 16126963 ns/op | 16206756 ns/op | |
63
- | 20 | 762519479 ns/op | 845552729 ns/op | |
63
+ | 20 | 762519479 ns/op | 845552729 ns/op | ` 85.99% ` / ` 63.78% ` |
64
64
65
65
\* compared to first solution
66
66
@@ -80,6 +80,7 @@ Using Go's built-in benchmarking with the [testing](https://pkg.go.dev/testing#h
80
80
| 12 | 10984420 ns/op | 16856988 ns/op | Baseline | [ Link] ( https://github.com/believer/advent-of-code/blob/7a220ed0e6deae74d0a293615e6348e6ce1a9a22/go/2024/puzzles/day12/main.go ) |
81
81
| 13 | 2900453 ns/op | 702380 ns/op | Baseline | [ Link] ( https://github.com/believer/advent-of-code/blob/0cf31064eb05f384cebe45cbeaf80ba90e0947ce/go/2024/puzzles/day13/main.go ) |
82
82
| 14 | 594981 ns/op | 56488050 ns/op | Baseline | [ Link] ( https://github.com/believer/advent-of-code/blob/a3f28eb2691d3e4be60ec56ab7f699332a2b3d31/go/2024/puzzles/day14/main.go ) |
83
+ | 20 | 762519479 ns/op | 845552729 ns/op | | [ Link] ( https://github.com/believer/advent-of-code/blob/305eba9ced6b40ecce606cf19f7cb9fc00e5ed73/go/2024/puzzles/day20/main.go ) |
83
84
84
85
## Running
85
86
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package main
2
2
3
3
import (
4
4
"fmt"
5
+ "sync"
5
6
6
7
"github.com/believer/aoc-2024/utils/files"
7
8
"github.com/believer/aoc-2024/utils/grid"
@@ -58,19 +59,32 @@ func race(name string, maxCheatTime int) int {
58
59
}
59
60
}
60
61
62
+ var mu sync.Mutex
63
+ var wg sync.WaitGroup
64
+
61
65
for p := range distances {
62
- for p2 := range distances {
63
- d := p .ManhattanDistance (p2 )
66
+ wg .Add (1 )
64
67
65
- if d > maxCheatTime {
66
- continue
67
- }
68
+ go func (p grid.Point ) {
69
+ defer wg .Done ()
70
+
71
+ for p2 := range distances {
72
+ d := p .ManhattanDistance (p2 )
68
73
69
- if distances [p2 ]- distances [p ]- d >= 100 {
70
- cheats ++
74
+ if d > maxCheatTime {
75
+ continue
76
+ }
77
+
78
+ if distances [p2 ]- distances [p ]- d >= 100 {
79
+ mu .Lock ()
80
+ cheats ++
81
+ mu .Unlock ()
82
+ }
71
83
}
72
- }
84
+ }( p )
73
85
}
74
86
87
+ wg .Wait ()
88
+
75
89
return cheats
76
90
}
You can’t perform that action at this time.
0 commit comments