Skip to content

Commit 16b9067

Browse files
committed
2025 day 7
1 parent ac94495 commit 16b9067

File tree

4 files changed

+99
-0
lines changed

4 files changed

+99
-0
lines changed

2025/7/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/7/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/7/common.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
"os"
6+
)
7+
8+
type P struct{ x, y int }
9+
10+
func parseInput() (map[P]struct{}, P, int) {
11+
var splitters = map[P]struct{}{}
12+
var start P
13+
14+
scanner := bufio.NewScanner(os.Stdin)
15+
var i int
16+
for i = 0; scanner.Scan(); i++ {
17+
line := scanner.Text()
18+
19+
for j, c := range line {
20+
switch c {
21+
case 'S':
22+
start = P{i, j}
23+
case '^':
24+
splitters[P{i, j}] = struct{}{}
25+
}
26+
}
27+
}
28+
return splitters, start, i
29+
}

2025/7/main1.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package main
2+
3+
import "fmt"
4+
5+
func main() {
6+
splitters, start, last := parseInput()
7+
beams := map[P]struct{}{P{start.x + 1, start.y}: {}}
8+
splits := 0
9+
for i := 2; i < last; i++ {
10+
nextBeams := map[P]struct{}{}
11+
for b := range beams {
12+
if _, ok := splitters[P{i, b.y}]; ok {
13+
splits++
14+
nextBeams[P{i, b.y - 1}] = struct{}{}
15+
nextBeams[P{i, b.y + 1}] = struct{}{}
16+
} else {
17+
nextBeams[P{i, b.y}] = struct{}{}
18+
}
19+
}
20+
beams = nextBeams
21+
}
22+
fmt.Println(splits)
23+
}

2025/7/main2.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package main
2+
3+
import "fmt"
4+
5+
func main() {
6+
splitters, start, last := parseInput()
7+
beams := map[P]int{P{start.x + 1, start.y}: 1}
8+
for i := 2; i < last; i++ {
9+
nextBeams := map[P]int{}
10+
for b, journeys := range beams {
11+
if _, ok := splitters[P{i, b.y}]; ok {
12+
nextBeams[P{i, b.y - 1}] += journeys
13+
nextBeams[P{i, b.y + 1}] += journeys
14+
} else {
15+
nextBeams[P{i, b.y}] += journeys
16+
}
17+
}
18+
beams = nextBeams
19+
}
20+
21+
paths := 0
22+
for _, journeys := range beams {
23+
paths += journeys
24+
}
25+
26+
fmt.Println(paths)
27+
}

0 commit comments

Comments
 (0)