From 60ffe95f69b5ef12abfbd166b439f397a2cc3da0 Mon Sep 17 00:00:00 2001 From: Kharec Date: Fri, 28 Nov 2025 12:53:29 +0100 Subject: [PATCH] feat: implement PartTwo using DFS recursion --- internal/2020/DaySeven/code.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/internal/2020/DaySeven/code.go b/internal/2020/DaySeven/code.go index dbe562b..83aa33c 100644 --- a/internal/2020/DaySeven/code.go +++ b/internal/2020/DaySeven/code.go @@ -90,5 +90,16 @@ func PartOne(data []string) int { } func PartTwo(data []string) int { - return 0 + forwardGraph := buildForwardGraph(data) + var countIndividualBags func(string) int + + countIndividualBags = func(bag string) int { + total := 0 + for _, child := range forwardGraph[bag] { + total += child.count + child.count*countIndividualBags(child.bag) + } + return total + } + + return countIndividualBags("shiny gold") }