empty struct instead of bool for better memory usage

This commit is contained in:
David 2021-12-12 13:29:41 -05:00
parent 137cfd379b
commit c09e706d42
1 changed files with 5 additions and 4 deletions

View File

@ -63,10 +63,10 @@ func doubleSmallAlready(visitedRooms []string) bool {
return false
}
func descend(rooms map[string]room, currentRoom string, path []string, success chan bool, canVisitSmallRoomTwice bool) {
func descend(rooms map[string]room, currentRoom string, path []string, success chan struct{}, canVisitSmallRoomTwice bool) {
var wg sync.WaitGroup
if currentRoom == "end" {
success <- true
success <- struct{}{}
return
}
for _, link := range rooms[currentRoom].links {
@ -107,10 +107,11 @@ func partOne() {
rooms[p[0]] = a
rooms[p[1]] = b
}
successes := make(chan bool, 10000)
successes := make(chan struct{}, 10000)
descend(rooms, "start", []string{}, successes, false)
fmt.Printf("%+v\n", len(successes))
}
func partTwo() {
scanner := makeScanner(false)
@ -133,7 +134,7 @@ func partTwo() {
rooms[p[0]] = a
rooms[p[1]] = b
}
successes := make(chan bool, 200000)
successes := make(chan struct{}, 200000)
descend(rooms, "start", []string{}, successes, true)
fmt.Printf("%+v\n", len(successes))
}