feat: solve day 10 part one
This commit is contained in:
@@ -35,6 +35,6 @@ go test ./cmd/01
|
|||||||
| 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. Fuck this guy. Part 2 was so much easier once part 1 was sorted out. |
|
| 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/) | Part 1 was such a nice break from the madness of day 8. Basically I need to go build some video games. |
|
| 09 | [Problem](https://adventofcode.com/2025/day/9) | [Solution](./cmd/09/) | Part 1 was such a nice break from the madness of day 8. Basically I need to go build some video games. |
|
||||||
| 10 | [Problem](https://adventofcode.com/2025/day/10) | [Solution](./cmd/10/) | |
|
| 10 | [Problem](https://adventofcode.com/2025/day/10) | [Solution](./cmd/10/) | Part 1 took me way to look cause I couldn't figure out how to generate all button press combinations. |
|
||||||
| 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/) | |
|
||||||
|
|||||||
+56
-3
@@ -2,7 +2,9 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -77,8 +79,60 @@ func NewButton(line string) button {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m machine) Configure([]bool) int {
|
func (m machine) Configure(desiredState []bool) int {
|
||||||
return 0
|
combinations := [][]bool{}
|
||||||
|
minPresses := math.MaxInt
|
||||||
|
numberOfButtons := len(m.buttons)
|
||||||
|
numberOfCombinations := int(math.Pow(2, float64(numberOfButtons)))
|
||||||
|
currentCombination := make([]bool, numberOfButtons)
|
||||||
|
|
||||||
|
for range numberOfCombinations {
|
||||||
|
temp := make([]bool, numberOfButtons)
|
||||||
|
copy(temp, currentCombination)
|
||||||
|
|
||||||
|
combinations = append(combinations, temp)
|
||||||
|
|
||||||
|
for j := range numberOfButtons {
|
||||||
|
if currentCombination[j] == false {
|
||||||
|
currentCombination[j] = true
|
||||||
|
break
|
||||||
|
} else {
|
||||||
|
currentCombination[j] = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, currentCombination := range combinations {
|
||||||
|
currentPresses := 0
|
||||||
|
switchesCopy := []bool{}
|
||||||
|
|
||||||
|
for _, v := range m.switches {
|
||||||
|
switchesCopy = append(switchesCopy, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
for bi, bs := range currentCombination {
|
||||||
|
if bs == false {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
currentPresses++
|
||||||
|
switchesToToggle := m.buttons[bi].switchesControlled
|
||||||
|
|
||||||
|
for _, switchToToggle := range switchesToToggle {
|
||||||
|
switchesCopy[switchToToggle] = !switchesCopy[switchToToggle]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if slices.Equal(switchesCopy, desiredState) == false {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if currentPresses < minPresses {
|
||||||
|
minPresses = currentPresses
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return minPresses
|
||||||
}
|
}
|
||||||
|
|
||||||
func SolvePartOne(filePath string) int {
|
func SolvePartOne(filePath string) int {
|
||||||
@@ -105,7 +159,6 @@ func SolvePartOne(filePath string) int {
|
|||||||
numberOfLights := len(lightDiagram)
|
numberOfLights := len(lightDiagram)
|
||||||
|
|
||||||
machine := NewMachine(numberOfLights, buttonsPart)
|
machine := NewMachine(numberOfLights, buttonsPart)
|
||||||
fmt.Println(machine)
|
|
||||||
buttonsPressed := machine.Configure(lightDiagram)
|
buttonsPressed := machine.Configure(lightDiagram)
|
||||||
total += buttonsPressed
|
total += buttonsPressed
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-2
@@ -6,8 +6,8 @@ import (
|
|||||||
solution "github.com/StevanFreeborn/advent-of-code-2025/cmd/10"
|
solution "github.com/StevanFreeborn/advent-of-code-2025/cmd/10"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSolvePartOne(t *testing.T) {
|
func TestSolvePartOneWithExampleInput(t *testing.T) {
|
||||||
expected := -1
|
expected := 7
|
||||||
|
|
||||||
result := solution.SolvePartOne("EXAMPLE.txt")
|
result := solution.SolvePartOne("EXAMPLE.txt")
|
||||||
|
|
||||||
@@ -15,3 +15,13 @@ func TestSolvePartOne(t *testing.T) {
|
|||||||
t.Errorf("got %d but wanted %d", result, expected)
|
t.Errorf("got %d but wanted %d", result, expected)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSolvePartOneWithInput(t *testing.T) {
|
||||||
|
expected := -1
|
||||||
|
|
||||||
|
result := solution.SolvePartOne("INPUT.txt")
|
||||||
|
|
||||||
|
if result != expected {
|
||||||
|
t.Errorf("got %d but wanted %d", result, expected)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user