feat: wip on day 11 part 2

This commit is contained in:
Stevan Freeborn
2025-12-22 07:34:39 -06:00
parent f199746830
commit 3cde531610
3 changed files with 86 additions and 7 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
**/*/EXAMPLE.txt **/*/EXAMPLE*.txt
**/*/INPUT.txt **/*/INPUT.txt
**/*/PROBLEM.md **/*/PROBLEM.md
+60 -4
View File
@@ -1,14 +1,18 @@
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"
"github.com/StevanFreeborn/advent-of-code-2025/internal/stack" "github.com/StevanFreeborn/advent-of-code-2025/internal/stack"
) )
const START_NODE = "you" const YOU_NODE = "you"
const END_NODE = "out" const OUT_NODE = "out"
const SVR_NODE = "svr"
const DAC_NODE = "dac"
const FFT_NODE = "fft"
func SolvePartOne(filePath string) int { func SolvePartOne(filePath string) int {
adjacencyList := map[string][]string{} adjacencyList := map[string][]string{}
@@ -21,13 +25,13 @@ func SolvePartOne(filePath string) int {
} }
stack := stack.New[string]() stack := stack.New[string]()
stack.Push(START_NODE) stack.Push(YOU_NODE)
pathCount := 0 pathCount := 0
for stack.IsEmpty() == false { for stack.IsEmpty() == false {
current, _ := stack.Pop() current, _ := stack.Pop()
if current == END_NODE { if current == OUT_NODE {
pathCount++ pathCount++
continue continue
} }
@@ -41,3 +45,55 @@ func SolvePartOne(filePath string) int {
return pathCount 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
}
+25 -2
View File
@@ -1,6 +1,7 @@
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"
@@ -9,10 +10,10 @@ import (
func TestSolvePartOneWithExampleInput(t *testing.T) { func TestSolvePartOneWithExampleInput(t *testing.T) {
expected := 5 expected := 5
result := solution.SolvePartOne("EXAMPLE.txt") result := solution.SolvePartOne("EXAMPLE_ONE.txt")
if result != expected { 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) 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)
}
}