Files
advent-of-code-2025/cmd/11/main.go
T

100 lines
1.7 KiB
Go
Raw Normal View History

2025-12-21 05:39:28 -06:00
package main
import (
2025-12-22 07:34:39 -06:00
"fmt"
2025-12-21 05:39:28 -06:00
"strings"
"github.com/StevanFreeborn/advent-of-code-2025/internal/file"
"github.com/StevanFreeborn/advent-of-code-2025/internal/stack"
)
2025-12-22 07:34:39 -06:00
const YOU_NODE = "you"
const OUT_NODE = "out"
const SVR_NODE = "svr"
const DAC_NODE = "dac"
const FFT_NODE = "fft"
2025-12-21 05:39:28 -06:00
func SolvePartOne(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[string]()
2025-12-22 07:34:39 -06:00
stack.Push(YOU_NODE)
2025-12-21 05:39:28 -06:00
pathCount := 0
for stack.IsEmpty() == false {
current, _ := stack.Pop()
2025-12-22 07:34:39 -06:00
if current == OUT_NODE {
2025-12-21 05:39:28 -06:00
pathCount++
continue
}
neighbors := adjacencyList[current]
for _, n := range neighbors {
stack.Push(n)
}
}
return pathCount
}
2025-12-22 07:34:39 -06:00
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
}