feat: wip on day 11 part 2
This commit is contained in:
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
**/*/EXAMPLE.txt
|
**/*/EXAMPLE*.txt
|
||||||
**/*/INPUT.txt
|
**/*/INPUT.txt
|
||||||
**/*/PROBLEM.md
|
**/*/PROBLEM.md
|
||||||
|
|
||||||
|
|||||||
+60
-4
@@ -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
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user