diff --git a/day6/main.go b/day6/main.go index fc15ce3..4f46eda 100644 --- a/day6/main.go +++ b/day6/main.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "runtime" "strings" "sync" @@ -27,6 +28,8 @@ const ( MapStateGuardRight ) +var amountOfGoroutines = 1 + func parseStringIntoMapLine(line string) []MapState { mapLine := []MapState{} for _, r := range line { @@ -229,6 +232,10 @@ func runCheck(area Map, addChan chan any, wg *sync.WaitGroup, isRoot bool) { checkedStates := []State{} for area.isGuardInMap() { if isRoot { + activeRoutines := runtime.NumGoroutine() + if activeRoutines > amountOfGoroutines { + amountOfGoroutines = activeRoutines + } nextElem, nextX, nextY := area.getFieldGuardIsFacing() // fmt.Printf("Guard in root is facing %d:%d of type %d\n", nextX, nextY, nextElem) // If is root and next field is empty, launch a new goroutine with that field being an obstacle @@ -294,4 +301,5 @@ func main() { wg.Wait() close(addChan) fmt.Printf("Task 2: %d\n", acc) + fmt.Printf("Peak nr of goroutines: %d\n", amountOfGoroutines) }