feat: solve part one using dfs approach

This commit is contained in:
2026-02-03 16:08:30 +01:00
parent a6eb8f9f22
commit 9de558024f

View File

@@ -17,7 +17,27 @@ func ParseInput(filepath string) []string {
} }
func PartOne(data []string) int { func PartOne(data []string) int {
return 0 graph := make(map[string][]string)
for _, line := range data {
device, outputsStr, _ := strings.Cut(line, ": ")
graph[device] = strings.Fields(outputsStr)
}
var countPaths func(string) int
countPaths = func(node string) int {
if node == "out" {
return 1
}
count := 0
for _, neighbor := range graph[node] {
count += countPaths(neighbor)
}
return count
}
return countPaths("you")
} }
func PartTwo(data []string) int { func PartTwo(data []string) int {