Skip to content

Commit c41ccfa

Browse files
committed
2025 day04
1 parent 42dfcdc commit c41ccfa

File tree

5 files changed

+26
-14
lines changed

5 files changed

+26
-14
lines changed

2025/day04/.bench

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"Lines":[{"Name":"Part 1","N":480,"NsPerOp":2287557,"AllocedBytesPerOp":0,"AllocsPerOp":0,"MBPerS":0,"Measured":1,"Ord":0},{"Name":"Part 2","N":33,"NsPerOp":35479323,"AllocedBytesPerOp":0,"AllocsPerOp":0,"MBPerS":0,"Measured":1,"Ord":0}],"Measured":1}
1+
{"Lines":[{"Name":"Part 1","N":667,"NsPerOp":1606148,"AllocedBytesPerOp":0,"AllocsPerOp":0,"MBPerS":0,"Measured":1,"Ord":0},{"Name":"Part 2","N":32,"NsPerOp":36528327,"AllocedBytesPerOp":0,"AllocsPerOp":0,"MBPerS":0,"Measured":1,"Ord":0}],"Measured":1}

2025/day04/main.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package main
22

33
import (
4+
"aocli/utils/maps"
45
_ "embed"
56
"image"
67
"os"
8+
"strings"
79
)
810

911
//go:embed input.txt
@@ -18,16 +20,22 @@ var delta = []image.Point{
1820
{-1, 1}, {0, 1}, {1, 1},
1921
}
2022

23+
var mapper map[image.Point]rune
24+
var rect image.Rectangle
25+
2126
func main() {
2227
// Check argv if we use test input or not
2328
if len(os.Args) > 1 && os.Args[1] == "test" {
2429
input = inputTest
2530
}
2631

32+
// Parse input once
33+
mapper, rect = maps.MakeImagePointMapRect(strings.Split(strings.TrimSpace(input), "\n"))
34+
2735
answer := doPartOne(input)
2836
println(answer)
2937

30-
answer = doPartTwo(input)
38+
answer = doPartTwo(mapper)
3139
println(answer)
3240
}
3341

2025/day04/main_test.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
11
package main
22

3-
import "testing"
3+
import (
4+
"aocli/utils/maps"
5+
"strings"
6+
"testing"
7+
)
48

59
func BenchmarkPartOne(b *testing.B) {
10+
// Parse input once before benchmark
11+
mapper, rect = maps.MakeImagePointMapRect(strings.Split(strings.TrimSpace(input), "\n"))
12+
13+
b.ResetTimer()
614
for n := 0; n < b.N; n++ {
715
doPartOne(input)
816
}
917
}
1018

1119
func BenchmarkPartTwo(b *testing.B) {
20+
// Parse input once before benchmark
21+
mapper, rect = maps.MakeImagePointMapRect(strings.Split(strings.TrimSpace(input), "\n"))
22+
23+
b.ResetTimer()
1224
for n := 0; n < b.N; n++ {
13-
doPartTwo(input)
25+
mapperCopy := maps.CopyMap(mapper)
26+
doPartTwo(mapperCopy)
1427
}
1528
}

2025/day04/part1.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
package main
22

3-
import (
4-
"aocli/utils/maps"
5-
"strings"
6-
)
7-
83
func doPartOne(input string) int {
9-
mapper, rect := maps.MakeImagePointMapRect(strings.Split(strings.TrimSpace(input), "\n"))
104
return countRemovable(mapper, rect)
115
}

2025/day04/part2.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
package main
22

33
import (
4-
"aocli/utils/maps"
54
"image"
6-
"strings"
75
)
86

9-
func doPartTwo(input string) int {
10-
mapper, rect := maps.MakeImagePointMapRect(strings.Split(strings.TrimSpace(input), "\n"))
7+
func doPartTwo(mapper map[image.Point]rune) int {
118
ans := 0
129

1310
for {

0 commit comments

Comments
 (0)