Skip to content

Commit 8e4b807

Browse files
committed
2025 day 3
1 parent 3836ea0 commit 8e4b807

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package main
2+
3+
func findJolts(bank string, digits int) int {
4+
output := 0
5+
idx := -1
6+
for i := digits; i > 0; i-- {
7+
var jolts int
8+
jolts, idx = findMax(bank, idx+1, len(bank)-i+1)
9+
output = output*10 + jolts
10+
}
11+
return output
12+
}
13+
14+
func findMax(list string, start, end int) (int, int) {
15+
var maxJolts uint8
16+
var idx int
17+
for i := start; i < end; i++ {
18+
if list[i] > maxJolts {
19+
maxJolts = list[i]
20+
idx = i
21+
}
22+
}
23+
return int(maxJolts - '0'), idx
24+
}

2025/3/main1.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
"fmt"
6+
"os"
7+
)
8+
9+
func main() {
10+
total := 0
11+
for scanner := bufio.NewScanner(os.Stdin); scanner.Scan(); {
12+
total += findJolts(scanner.Text(), 2)
13+
}
14+
fmt.Println(total)
15+
}

2025/3/main2.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
"fmt"
6+
"os"
7+
)
8+
9+
func main() {
10+
total := 0
11+
for scanner := bufio.NewScanner(os.Stdin); scanner.Scan(); {
12+
total += findJolts(scanner.Text(), 12)
13+
}
14+
fmt.Println(total)
15+
}

0 commit comments

Comments
 (0)