feat: solve day 8 part 2...we in this bitch
This commit is contained in:
@@ -24,17 +24,17 @@ go test ./cmd/01
|
|||||||
|
|
||||||
## Challenges
|
## Challenges
|
||||||
|
|
||||||
| Day | Problem | Solution | Notes |
|
| Day | Problem | Solution | Notes |
|
||||||
|-----|-------------------------------------------------|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|-----|-------------------------------------------------|-----------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
| 01 | [Problem](https://adventofcode.com/2025/day/1) | [Solution](./cmd/01/) | Part 1 seemed straight forward enough. Part 2 completely stumped me. The trickiest part was not counting zero's twice when you ended and then started from there. |
|
| 01 | [Problem](https://adventofcode.com/2025/day/1) | [Solution](./cmd/01/) | Part 1 seemed straight forward enough. Part 2 completely stumped me. The trickiest part was not counting zero's twice when you ended and then started from there. |
|
||||||
| 02 | [Problem](https://adventofcode.com/2025/day/2) | [Solution](./cmd/02/) | Part 1 should have been super straight-forward, but some whitespace screwed up my parsing of the final range. I some how was able to stumble over a solution to part 2 rather blindly. |
|
| 02 | [Problem](https://adventofcode.com/2025/day/2) | [Solution](./cmd/02/) | Part 1 should have been super straight-forward, but some whitespace screwed up my parsing of the final range. I some how was able to stumble over a solution to part 2 rather blindly. |
|
||||||
| 03 | [Problem](https://adventofcode.com/2025/day/3) | [Solution](./cmd/03/) | Part 1 intuitively makes you think you only care about highest nums, but then you need to consider placement. I once again tripped over the solution using a stack. However chat morally supported me the whole time. |
|
| 03 | [Problem](https://adventofcode.com/2025/day/3) | [Solution](./cmd/03/) | Part 1 intuitively makes you think you only care about highest nums, but then you need to consider placement. I once again tripped over the solution using a stack. However chat morally supported me the whole time. |
|
||||||
| 04 | [Problem](https://adventofcode.com/2025/day/4) | [Solution](./cmd/04/) | Part 1 was by far the most straight-forward challenge so far. This was easiest day of AoC this year by far. |
|
| 04 | [Problem](https://adventofcode.com/2025/day/4) | [Solution](./cmd/04/) | Part 1 was by far the most straight-forward challenge so far. This was easiest day of AoC this year by far. |
|
||||||
| 05 | [Problem](https://adventofcode.com/2025/day/5) | [Solution](./cmd/05/) | Part 1 was fairly straight forward. Merging ranges was trickiest bit. I feel like I'm being led into a trap with how straight forward today was. |
|
| 05 | [Problem](https://adventofcode.com/2025/day/5) | [Solution](./cmd/05/) | Part 1 was fairly straight forward. Merging ranges was trickiest bit. I feel like I'm being led into a trap with how straight forward today was. |
|
||||||
| 06 | [Problem](https://adventofcode.com/2025/day/6) | [Solution](./cmd/06/) | Part 1 I don't think it is the best solution, but it does solve it. I kicked ass on part 2. 🥳 |
|
| 06 | [Problem](https://adventofcode.com/2025/day/6) | [Solution](./cmd/06/) | Part 1 I don't think it is the best solution, but it does solve it. I kicked ass on part 2. 🥳 |
|
||||||
| 07 | [Problem](https://adventofcode.com/2025/day/7) | [Solution](./cmd/07/) | FIFO for life. 🤣. Fuck me...part 2 I found really difficult and the use of DFS was obvious, but doing the memoizing was not. |
|
| 07 | [Problem](https://adventofcode.com/2025/day/7) | [Solution](./cmd/07/) | FIFO for life. 🤣. Fuck me...part 2 I found really difficult and the use of DFS was obvious, but doing the memoizing was not. |
|
||||||
| 08 | [Problem](https://adventofcode.com/2025/day/8) | [Solution](./cmd/08/) | Part 1 had me down bad. I was on the right track with my original solution, but ended up doing it in a brute force way then figuring out my mistake with the original. |
|
| 08 | [Problem](https://adventofcode.com/2025/day/8) | [Solution](./cmd/08/) | Part 1 had me down bad. I was on the right track with my original solution, but ended up doing it in a brute force way then figuring out my mistake with the original. Fuck this guy. Part 2 was so much easier once part 1 was sorted out. |
|
||||||
| 09 | [Problem](https://adventofcode.com/2025/day/9) | [Solution](./cmd/09/) | |
|
| 09 | [Problem](https://adventofcode.com/2025/day/9) | [Solution](./cmd/09/) | |
|
||||||
| 10 | [Problem](https://adventofcode.com/2025/day/10) | [Solution](./cmd/10/) | |
|
| 10 | [Problem](https://adventofcode.com/2025/day/10) | [Solution](./cmd/10/) | |
|
||||||
| 11 | [Problem](https://adventofcode.com/2025/day/11) | [Solution](./cmd/11/) | |
|
| 11 | [Problem](https://adventofcode.com/2025/day/11) | [Solution](./cmd/11/) | |
|
||||||
| 12 | [Problem](https://adventofcode.com/2025/day/12) | [Solution](./cmd/12/) | |
|
| 12 | [Problem](https://adventofcode.com/2025/day/12) | [Solution](./cmd/12/) | |
|
||||||
|
|||||||
@@ -9,6 +9,50 @@ import (
|
|||||||
"github.com/StevanFreeborn/advent-of-code-2025/internal/queue"
|
"github.com/StevanFreeborn/advent-of-code-2025/internal/queue"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func SolvePartTwo(filePath string) int {
|
||||||
|
boxes := []box.Box{}
|
||||||
|
|
||||||
|
for line := range file.ReadLines(filePath) {
|
||||||
|
boxes = append(boxes, box.From(line))
|
||||||
|
}
|
||||||
|
|
||||||
|
estimator := estimator.From(boxes)
|
||||||
|
circuitsMap := estimator.CreateMap()
|
||||||
|
|
||||||
|
numberOfSets := len(boxes)
|
||||||
|
|
||||||
|
for _, connection := range estimator.PossibleConnections() {
|
||||||
|
startRoot := circuitsMap.FindRootBoxFor(connection.Start())
|
||||||
|
endRoot := circuitsMap.FindRootBoxFor(connection.End())
|
||||||
|
|
||||||
|
if startRoot == endRoot {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
startRootValue, _ := circuitsMap.GetValueFor(startRoot)
|
||||||
|
endRootValue, _ := circuitsMap.GetValueFor(endRoot)
|
||||||
|
|
||||||
|
if startRootValue.Size() < endRootValue.Size() {
|
||||||
|
startRootValue.UpdateParent(endRoot)
|
||||||
|
endRootValue.IncreaseSize(startRootValue.Size())
|
||||||
|
} else {
|
||||||
|
endRootValue.UpdateParent(startRoot)
|
||||||
|
startRootValue.IncreaseSize(endRootValue.Size())
|
||||||
|
}
|
||||||
|
|
||||||
|
circuitsMap.UpdateValueFor(startRoot, startRootValue)
|
||||||
|
circuitsMap.UpdateValueFor(endRoot, endRootValue)
|
||||||
|
|
||||||
|
numberOfSets--
|
||||||
|
|
||||||
|
if numberOfSets == 1 {
|
||||||
|
return connection.Start().X() * connection.End().X()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
func SolvePartOne(filePath string, numOfConnections int) int {
|
func SolvePartOne(filePath string, numOfConnections int) int {
|
||||||
boxes := []box.Box{}
|
boxes := []box.Box{}
|
||||||
|
|
||||||
|
|||||||
+22
-2
@@ -17,7 +17,7 @@ func TestSolvePartOneWithExampleInput(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSolvePartOneWithInput(t *testing.T) {
|
func TestSolvePartOneWithInput(t *testing.T) {
|
||||||
expected := 62186
|
expected := 62_186
|
||||||
|
|
||||||
result := solution.SolvePartOne("INPUT.txt", 1000)
|
result := solution.SolvePartOne("INPUT.txt", 1000)
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ func TestSolvePartOneAgainWithExampleInput(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSolvePartOneAgainWithInput(t *testing.T) {
|
func TestSolvePartOneAgainWithInput(t *testing.T) {
|
||||||
expected := 62186
|
expected := 62_186
|
||||||
|
|
||||||
result := solution.SolvePartOneAgain("INPUT.txt", 1000)
|
result := solution.SolvePartOneAgain("INPUT.txt", 1000)
|
||||||
|
|
||||||
@@ -45,3 +45,23 @@ func TestSolvePartOneAgainWithInput(t *testing.T) {
|
|||||||
t.Errorf("SolvePartOneAgain returned %d, expected %d", result, expected)
|
t.Errorf("SolvePartOneAgain returned %d, expected %d", result, expected)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSolvePartTwoWithExampleInput(t *testing.T) {
|
||||||
|
expected := 25_272
|
||||||
|
|
||||||
|
result := solution.SolvePartTwo("EXAMPLE.txt")
|
||||||
|
|
||||||
|
if result != expected {
|
||||||
|
t.Errorf("SolvePartTwo returned %d, expected %d", result, expected)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSolvePartTwoWithInput(t *testing.T) {
|
||||||
|
expected := 8_420_405_530
|
||||||
|
|
||||||
|
result := solution.SolvePartTwo("INPUT.txt")
|
||||||
|
|
||||||
|
if result != expected {
|
||||||
|
t.Errorf("SolvePartTwo returned %d, expected %d", result, expected)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user