feat: solved day 11 part 2

This commit is contained in:
Stevan Freeborn
2025-12-22 16:35:28 -06:00
parent b78ca2d2b9
commit 1654f7d9c9
2 changed files with 9 additions and 87 deletions
+8 -63
View File
@@ -1,7 +1,6 @@
package main package main
import ( import (
"fmt"
"strings" "strings"
"github.com/StevanFreeborn/advent-of-code-2025/internal/file" "github.com/StevanFreeborn/advent-of-code-2025/internal/file"
@@ -47,60 +46,8 @@ func SolvePartOne(filePath string) int {
return pathCount return pathCount
} }
type node struct {
value string
fftSeen bool
dacSeen bool
}
func SolvePartTwo(filePath string) int { func SolvePartTwo(filePath string) int {
adjacencyList := map[string][]string{} 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{} inDegrees := map[string]int{}
allNodes := map[string]bool{} 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 := map[string]int{}
pathsCount[SVR_NODE] = 1 pathsCount[start] = 1
for _, item := range processOrder { for _, item := range processOrder {
if pathsCount[item] == 0 { if pathsCount[item] == 0 {
@@ -160,13 +113,5 @@ func SolvePartTwoAgain(filePath string) int {
} }
} }
// TODO: Could I process the graph return pathsCount[end]
// 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
} }
+1 -24
View File
@@ -1,7 +1,6 @@
package main_test package main_test
import ( import (
"fmt"
"testing" "testing"
solution "github.com/StevanFreeborn/advent-of-code-2025/cmd/11" solution "github.com/StevanFreeborn/advent-of-code-2025/cmd/11"
@@ -38,9 +37,7 @@ func TestSolvePartTwoWithExampleInput(t *testing.T) {
} }
func TestSolvePartTwoWithInput(t *testing.T) { func TestSolvePartTwoWithInput(t *testing.T) {
expected := -1 expected := 393_474_305_030_400
fmt.Println("HERE")
result := solution.SolvePartTwo("INPUT.txt") result := solution.SolvePartTwo("INPUT.txt")
@@ -48,23 +45,3 @@ func TestSolvePartTwoWithInput(t *testing.T) {
t.Errorf("SolvePartTwo(INPUT.txt) = %d; want %d", result, expected) 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)
}
}