From c09e706d42d644f48d99a80a332e8b72676aa67c Mon Sep 17 00:00:00 2001 From: David Ashby Date: Sun, 12 Dec 2021 13:29:41 -0500 Subject: [PATCH] empty struct instead of bool for better memory usage --- 12/main.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/12/main.go b/12/main.go index 702711b..be73e21 100644 --- a/12/main.go +++ b/12/main.go @@ -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)) }