Added peak amount of goroutines as final stat for day 6
This commit is contained in:
parent
1014cbb42c
commit
b7325b93f6
1 changed files with 8 additions and 0 deletions
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue