Skip to content

Commit 38ecff2

Browse files
committed
2025, day 10, part1
1 parent 89a7080 commit 38ecff2

File tree

3 files changed

+114
-0
lines changed

3 files changed

+114
-0
lines changed

2025/10/Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
input:
2+
http "https://adventofcode.com/2025/day/10/input" "Cookie:session=${AOC_SESSION};" >input
3+
4+
main1:
5+
go build -o main1 main1.go common.go
6+
7+
main2:
8+
go build -o main2 main2.go common.go
9+
10+
.PHONY: run1 run2 clean
11+
12+
run1: main1 input
13+
./main1 <input
14+
15+
run2: main2 input
16+
./main2 <input
17+
18+
clean:
19+
rm -f main1 main2 input
20+

2025/10/common.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
"os"
6+
"strconv"
7+
"strings"
8+
)
9+
10+
type Machine struct {
11+
Indicator uint16
12+
Buttons []uint16
13+
ButtonsInt [][]int
14+
Joltage []int
15+
}
16+
17+
func parseInput() []Machine {
18+
var list []Machine
19+
20+
for scanner := bufio.NewScanner(os.Stdin); scanner.Scan(); {
21+
tokens := strings.Split(scanner.Text(), " ")
22+
23+
indicatorS := strings.Trim(tokens[0], "[]")
24+
var indicator uint16
25+
for i, c := range indicatorS {
26+
if c == '#' {
27+
indicator |= 1 << uint16(len(indicatorS)-i-1)
28+
}
29+
}
30+
31+
var buttons []uint16
32+
var buttonsInt [][]int
33+
for i := 1; i < len(tokens)-1; i++ {
34+
buttonS := strings.Split(strings.Trim(tokens[i], "()"), ",")
35+
buttonInt := make([]int, len(buttonS))
36+
var button uint16
37+
for j, b := range buttonS {
38+
n, _ := strconv.Atoi(b)
39+
buttonInt[j] = n
40+
button |= 1 << uint16(len(indicatorS)-n-1)
41+
}
42+
buttons = append(buttons, button)
43+
buttonsInt = append(buttonsInt, buttonInt)
44+
}
45+
46+
joltageS := strings.Split(strings.Trim(tokens[len(tokens)-1], "{}"), ",")
47+
joltage := make([]int, len(joltageS))
48+
for i := range joltageS {
49+
joltage[i], _ = strconv.Atoi(joltageS[i])
50+
}
51+
list = append(list, Machine{indicator, buttons, buttonsInt, joltage})
52+
}
53+
return list
54+
}

2025/10/main1.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package main
2+
3+
import "fmt"
4+
5+
func main() {
6+
list := parseInput()
7+
sum := 0
8+
for _, m := range list {
9+
sum += m.BFS()
10+
}
11+
fmt.Println(sum)
12+
}
13+
14+
func (m Machine) BFS() int {
15+
if m.Indicator == 0 {
16+
return 0
17+
}
18+
19+
dist := map[uint16]int{0: 0}
20+
queue := []uint16{0}
21+
for len(queue) > 0 {
22+
var curr uint16
23+
curr, queue = queue[0], queue[1:]
24+
currDist := dist[curr]
25+
26+
for _, b := range m.Buttons {
27+
nextVal := curr ^ b
28+
29+
if nextVal == m.Indicator {
30+
return currDist + 1
31+
}
32+
33+
if _, ok := dist[nextVal]; !ok {
34+
dist[nextVal] = currDist + 1
35+
queue = append(queue, nextVal)
36+
}
37+
}
38+
}
39+
return -1
40+
}

0 commit comments

Comments
 (0)