advent-of-code

Perserverance, or the lack thereof

git clone git://git.shimmy1996.com/advent-of-code.git
commit 05c0af8e61a4eff0ebabdcc79973845e1d6afdaf
parent dd364989ec39fe7183cc73b7320368b9418e0c57
Author: Shimmy Xu <shimmy.xu@shimmy1996.com>
Date:   Tue,  8 Dec 2020 19:46:22 -0600

Simplify logic

Diffstat:
M2020/day07/main.go | 15++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/2020/day07/main.go b/2020/day07/main.go
@@ -61,16 +61,13 @@ func part2(input map[string]map[string]int) (count_tot int) {
 	queue := []string{"shiny gold"}
 	count := []int{1}
 	for len(queue) > 0 {
-		curr := queue[0]
-		queue = queue[1:]
-		curr_count := count[0]
-		count = count[1:]
-		count_tot += curr_count
-		for k, v := range input[curr] {
+		for k, v := range input[queue[0]] {
 			queue = append(queue, k)
-			count = append(count, curr_count*v)
+			count = append(count, count[0]*v)
+			count_tot += count[0] * v
 		}
+		queue = queue[1:]
+		count = count[1:]
 	}
-	// don't count initial bag
-	return count_tot - 1
+	return
 }