From 3cde5316102c389769a1db9f05a5fe9d507e2a05 Mon Sep 17 00:00:00 2001 From: Stevan Freeborn <65925598+StevanFreeborn@users.noreply.github.com> Date: Mon, 22 Dec 2025 07:34:39 -0600 Subject: [PATCH 1/3] feat: wip on day 11 part 2 --- .gitignore | 2 +- cmd/11/main.go | 64 ++++++++++++++++++++++++++++++++++++++++++--- cmd/11/main_test.go | 27 +++++++++++++++++-- 3 files changed, 86 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 4b1d5ae..5134f6f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -**/*/EXAMPLE.txt +**/*/EXAMPLE*.txt **/*/INPUT.txt **/*/PROBLEM.md diff --git a/cmd/11/main.go b/cmd/11/main.go index 3abab4c..fe2c3c5 100644 --- a/cmd/11/main.go +++ b/cmd/11/main.go @@ -1,14 +1,18 @@ package main import ( + "fmt" "strings" "github.com/StevanFreeborn/advent-of-code-2025/internal/file" "github.com/StevanFreeborn/advent-of-code-2025/internal/stack" ) -const START_NODE = "you" -const END_NODE = "out" +const YOU_NODE = "you" +const OUT_NODE = "out" +const SVR_NODE = "svr" +const DAC_NODE = "dac" +const FFT_NODE = "fft" func SolvePartOne(filePath string) int { adjacencyList := map[string][]string{} @@ -21,13 +25,13 @@ func SolvePartOne(filePath string) int { } stack := stack.New[string]() - stack.Push(START_NODE) + stack.Push(YOU_NODE) pathCount := 0 for stack.IsEmpty() == false { current, _ := stack.Pop() - if current == END_NODE { + if current == OUT_NODE { pathCount++ continue } @@ -41,3 +45,55 @@ func SolvePartOne(filePath string) int { return pathCount } + +type node struct { + value string + numberOfParentPaths int +} + +func SolvePartTwo(filePath string) int { + adjacencyList := map[string][]string{} + + for line := range file.ReadLines(filePath) { + parts := strings.Split(line, ": ") + from := parts[0] + toList := strings.Split(parts[1], " ") + adjacencyList[from] = toList + } + + stack := stack.New[node]() + stack.Push(node{ + value: SVR_NODE, + }) + visisted := map[node]int{} + pathCount := 0 + + for stack.IsEmpty() == false { + current, _ := stack.Pop() + + _, ok := visisted[current] + + if ok { + visisted[current]++ + } else { + visisted[current] = 1 + } + + if current.value == OUT_NODE { + pathCount++ + continue + } + + neighbors := adjacencyList[current.value] + + for _, n := range neighbors { + stack.Push(node{ + value: n, + }) + } + } + + fmt.Println(visisted) + + return pathCount +} diff --git a/cmd/11/main_test.go b/cmd/11/main_test.go index dd5ab04..9e95f53 100644 --- a/cmd/11/main_test.go +++ b/cmd/11/main_test.go @@ -1,6 +1,7 @@ package main_test import ( + "fmt" "testing" solution "github.com/StevanFreeborn/advent-of-code-2025/cmd/11" @@ -9,10 +10,10 @@ import ( func TestSolvePartOneWithExampleInput(t *testing.T) { expected := 5 - result := solution.SolvePartOne("EXAMPLE.txt") + result := solution.SolvePartOne("EXAMPLE_ONE.txt") if result != expected { - t.Errorf("SolvePartOne(EXAMPLE.txt) = %d; want %d", result, expected) + t.Errorf("SolvePartOne(EXAMPLE_ONE.txt) = %d; want %d", result, expected) } } @@ -25,3 +26,25 @@ func TestSolvePartOneWithInput(t *testing.T) { t.Errorf("SolvePartOne(INPUT.txt) = %d; want %d", result, expected) } } + +func TestSolvePartTwoWithExampleInput(t *testing.T) { + expected := 2 + + result := solution.SolvePartTwo("EXAMPLE_TWO.txt") + + if result != expected { + t.Errorf("SolvePartTwo(EXAMPLE_TWO.txt) = %d; want %d", result, expected) + } +} + +func TestSolvePartTwoWithInput(t *testing.T) { + expected := -1 + + fmt.Println("HERE") + + result := solution.SolvePartTwo("INPUT.txt") + + if result != expected { + t.Errorf("SolvePartTwo(INPUT.txt) = %d; want %d", result, expected) + } +} From b78ca2d2b97afc203eeaf0d0501774bfaf09b844 Mon Sep 17 00:00:00 2001 From: Stevan Freeborn <65925598+StevanFreeborn@users.noreply.github.com> Date: Mon, 22 Dec 2025 08:30:19 -0600 Subject: [PATCH 2/3] feat: I think I'm getting closer --- cmd/11/main.go | 99 +++++++++++++++++++++++++++++++++++++++------ cmd/11/main_test.go | 20 +++++++++ 2 files changed, 106 insertions(+), 13 deletions(-) diff --git a/cmd/11/main.go b/cmd/11/main.go index fe2c3c5..2e0ac20 100644 --- a/cmd/11/main.go +++ b/cmd/11/main.go @@ -5,6 +5,7 @@ import ( "strings" "github.com/StevanFreeborn/advent-of-code-2025/internal/file" + "github.com/StevanFreeborn/advent-of-code-2025/internal/queue" "github.com/StevanFreeborn/advent-of-code-2025/internal/stack" ) @@ -47,8 +48,9 @@ func SolvePartOne(filePath string) int { } type node struct { - value string - numberOfParentPaths int + value string + fftSeen bool + dacSeen bool } func SolvePartTwo(filePath string) int { @@ -65,21 +67,20 @@ func SolvePartTwo(filePath string) int { stack.Push(node{ value: SVR_NODE, }) - visisted := map[node]int{} pathCount := 0 for stack.IsEmpty() == false { current, _ := stack.Pop() - _, ok := visisted[current] - - if ok { - visisted[current]++ - } else { - visisted[current] = 1 + if current.value == FFT_NODE { + current.fftSeen = true } - if current.value == OUT_NODE { + if current.value == DAC_NODE { + current.dacSeen = true + } + + if current.value == OUT_NODE && current.dacSeen && current.fftSeen { pathCount++ continue } @@ -88,12 +89,84 @@ func SolvePartTwo(filePath string) int { for _, n := range neighbors { stack.Push(node{ - value: n, + value: n, + fftSeen: current.fftSeen, + dacSeen: current.dacSeen, }) } } - fmt.Println(visisted) - return pathCount } + +func SolvePartTwoAgain(filePath string) int { + adjacencyList := map[string][]string{} + inDegrees := map[string]int{} + allNodes := map[string]bool{} + + for line := range file.ReadLines(filePath) { + parts := strings.Split(line, ": ") + from := parts[0] + toList := strings.Split(parts[1], " ") + + allNodes[from] = true + + _, existingInDegrees := inDegrees[from] + + if existingInDegrees == false { + inDegrees[from] = 0 + } + + for _, to := range toList { + allNodes[to] = true + adjacencyList[from] = append(adjacencyList[from], to) + inDegrees[to]++ + } + } + + queue := queue.New[string]() + + for node := range allNodes { + if inDegrees[node] == 0 { + queue.Enqueue(node) + } + } + + processOrder := []string{} + + for queue.IsEmpty() == false { + current, _ := queue.Dequeue() + processOrder = append(processOrder, current) + + for _, neighbor := range adjacencyList[current] { + inDegrees[neighbor]-- + + if inDegrees[neighbor] == 0 { + queue.Enqueue(neighbor) + } + } + } + + pathsCount := map[string]int{} + pathsCount[SVR_NODE] = 1 + + for _, item := range processOrder { + if pathsCount[item] == 0 { + continue + } + + for _, n := range adjacencyList[item] { + pathsCount[n] += pathsCount[item] + } + } + + // TODO: Could I process the graph + // in smaller pieces and then multiply + // those path to figure out what the + // total number of paths are. + fmt.Println(pathsCount[OUT_NODE]) + fmt.Println(pathsCount[DAC_NODE]) + fmt.Println(pathsCount[FFT_NODE]) + + return 0 +} diff --git a/cmd/11/main_test.go b/cmd/11/main_test.go index 9e95f53..29d9ea2 100644 --- a/cmd/11/main_test.go +++ b/cmd/11/main_test.go @@ -48,3 +48,23 @@ func TestSolvePartTwoWithInput(t *testing.T) { t.Errorf("SolvePartTwo(INPUT.txt) = %d; want %d", result, expected) } } + +func TestSolvePartTwoAgainWithExampleInput(t *testing.T) { + expected := 2 + + result := solution.SolvePartTwoAgain("EXAMPLE_TWO.txt") + + if result != expected { + t.Errorf("SolvePartTwoAgain(EXAMPLE_TWO.txt) = %d; want %d", result, expected) + } +} + +func TestSolvePartTwoAgainWithInput(t *testing.T) { + expected := -1 + + result := solution.SolvePartTwoAgain("INPUT.txt") + + if result != expected { + t.Errorf("SolvePartTwoAgain(INPUT.txt) = %d; want %d", result, expected) + } +} From 1654f7d9c96729d5a48142c144d26c8f6314fe6a Mon Sep 17 00:00:00 2001 From: Stevan Freeborn <65925598+StevanFreeborn@users.noreply.github.com> Date: Mon, 22 Dec 2025 16:35:28 -0600 Subject: [PATCH 3/3] feat: solved day 11 part 2 --- cmd/11/main.go | 71 +++++---------------------------------------- cmd/11/main_test.go | 25 +--------------- 2 files changed, 9 insertions(+), 87 deletions(-) diff --git a/cmd/11/main.go b/cmd/11/main.go index 2e0ac20..a54a013 100644 --- a/cmd/11/main.go +++ b/cmd/11/main.go @@ -1,7 +1,6 @@ package main import ( - "fmt" "strings" "github.com/StevanFreeborn/advent-of-code-2025/internal/file" @@ -47,60 +46,8 @@ func SolvePartOne(filePath string) int { return pathCount } -type node struct { - value string - fftSeen bool - dacSeen bool -} - func SolvePartTwo(filePath string) int { adjacencyList := map[string][]string{} - - for line := range file.ReadLines(filePath) { - parts := strings.Split(line, ": ") - from := parts[0] - toList := strings.Split(parts[1], " ") - adjacencyList[from] = toList - } - - stack := stack.New[node]() - stack.Push(node{ - value: SVR_NODE, - }) - pathCount := 0 - - for stack.IsEmpty() == false { - current, _ := stack.Pop() - - if current.value == FFT_NODE { - current.fftSeen = true - } - - if current.value == DAC_NODE { - current.dacSeen = true - } - - if current.value == OUT_NODE && current.dacSeen && current.fftSeen { - pathCount++ - continue - } - - neighbors := adjacencyList[current.value] - - for _, n := range neighbors { - stack.Push(node{ - value: n, - fftSeen: current.fftSeen, - dacSeen: current.dacSeen, - }) - } - } - - return pathCount -} - -func SolvePartTwoAgain(filePath string) int { - adjacencyList := map[string][]string{} inDegrees := map[string]int{} allNodes := map[string]bool{} @@ -147,8 +94,14 @@ func SolvePartTwoAgain(filePath string) int { } } + pathA := countPaths(SVR_NODE, FFT_NODE, processOrder, adjacencyList) * countPaths(FFT_NODE, DAC_NODE, processOrder, adjacencyList) * countPaths(DAC_NODE, OUT_NODE, processOrder, adjacencyList) + pathB := countPaths(SVR_NODE, DAC_NODE, processOrder, adjacencyList) * countPaths(DAC_NODE, FFT_NODE, processOrder, adjacencyList) * countPaths(FFT_NODE, OUT_NODE, processOrder, adjacencyList) + return pathA + pathB +} + +func countPaths(start string, end string, processOrder []string, adjacencyList map[string][]string) int { pathsCount := map[string]int{} - pathsCount[SVR_NODE] = 1 + pathsCount[start] = 1 for _, item := range processOrder { if pathsCount[item] == 0 { @@ -160,13 +113,5 @@ func SolvePartTwoAgain(filePath string) int { } } - // TODO: Could I process the graph - // in smaller pieces and then multiply - // those path to figure out what the - // total number of paths are. - fmt.Println(pathsCount[OUT_NODE]) - fmt.Println(pathsCount[DAC_NODE]) - fmt.Println(pathsCount[FFT_NODE]) - - return 0 + return pathsCount[end] } diff --git a/cmd/11/main_test.go b/cmd/11/main_test.go index 29d9ea2..950f6c1 100644 --- a/cmd/11/main_test.go +++ b/cmd/11/main_test.go @@ -1,7 +1,6 @@ package main_test import ( - "fmt" "testing" solution "github.com/StevanFreeborn/advent-of-code-2025/cmd/11" @@ -38,9 +37,7 @@ func TestSolvePartTwoWithExampleInput(t *testing.T) { } func TestSolvePartTwoWithInput(t *testing.T) { - expected := -1 - - fmt.Println("HERE") + expected := 393_474_305_030_400 result := solution.SolvePartTwo("INPUT.txt") @@ -48,23 +45,3 @@ func TestSolvePartTwoWithInput(t *testing.T) { t.Errorf("SolvePartTwo(INPUT.txt) = %d; want %d", result, expected) } } - -func TestSolvePartTwoAgainWithExampleInput(t *testing.T) { - expected := 2 - - result := solution.SolvePartTwoAgain("EXAMPLE_TWO.txt") - - if result != expected { - t.Errorf("SolvePartTwoAgain(EXAMPLE_TWO.txt) = %d; want %d", result, expected) - } -} - -func TestSolvePartTwoAgainWithInput(t *testing.T) { - expected := -1 - - result := solution.SolvePartTwoAgain("INPUT.txt") - - if result != expected { - t.Errorf("SolvePartTwoAgain(INPUT.txt) = %d; want %d", result, expected) - } -}