Skip to content

Commit 0eae0ec

Browse files
committed
2025 day12
1 parent eef667d commit 0eae0ec

File tree

5 files changed

+90
-0
lines changed

5 files changed

+90
-0
lines changed

2025/day12/.bench

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"Lines":[{"Name":"Part 1","N":3043,"NsPerOp":373346,"AllocedBytesPerOp":0,"AllocsPerOp":0,"MBPerS":0,"Measured":1,"Ord":0}],"Measured":1}

2025/day12/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<!-- You can add some comments here if you want to :D -->

2025/day12/main.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package main
2+
3+
import (
4+
_ "embed"
5+
"os"
6+
)
7+
8+
//go:embed input.txt
9+
var input string
10+
11+
//go:embed input_test.txt
12+
var inputTest string
13+
14+
func main() {
15+
// Check argv if we use test input or not
16+
if len(os.Args) > 1 && os.Args[1] == "test" {
17+
input = inputTest
18+
}
19+
20+
answer := doPartOne(input)
21+
println(answer)
22+
}

2025/day12/main_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package main
2+
3+
import "testing"
4+
5+
func BenchmarkPartOne(b *testing.B) {
6+
for n := 0; n < b.N; n++ {
7+
doPartOne(input)
8+
}
9+
}

2025/day12/part1.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package main
2+
3+
import (
4+
"aocli/utils"
5+
"fmt"
6+
"strings"
7+
)
8+
9+
func doPartOne(input string) int {
10+
parts := strings.Split(strings.TrimSpace(input), "\n\n")
11+
12+
// Precompute present counts (count '#' symbols in each present pattern)
13+
numPresents := len(parts) - 1
14+
presents := make([]int, numPresents)
15+
for i := 0; i < numPresents; i++ {
16+
presents[i] = strings.Count(parts[i], "#")
17+
}
18+
19+
ans := 0
20+
lines := strings.Split(parts[numPresents], "\n")
21+
22+
for _, line := range lines {
23+
// Parse dimensions and gift counts
24+
colonIdx := strings.Index(line, ": ")
25+
if colonIdx == -1 {
26+
continue
27+
}
28+
29+
var x, y int
30+
fmt.Sscanf(line[:colonIdx], "%dx%d", &x, &y)
31+
area := x * y
32+
33+
// Calculate total present area
34+
totalpresentarea := 0
35+
giftStart := colonIdx + 2
36+
for i := 0; giftStart < len(line); i++ {
37+
// Parse next number
38+
spaceIdx := strings.IndexByte(line[giftStart:], ' ')
39+
var numStr string
40+
if spaceIdx == -1 {
41+
numStr = line[giftStart:]
42+
giftStart = len(line)
43+
} else {
44+
numStr = line[giftStart : giftStart+spaceIdx]
45+
giftStart += spaceIdx + 1
46+
}
47+
totalpresentarea += utils.Atoi(numStr) * presents[i]
48+
}
49+
50+
// Check if sleigh has enough space
51+
if totalpresentarea <= area && area > totalpresentarea+(totalpresentarea/5) {
52+
ans++
53+
}
54+
}
55+
56+
return ans
57+
}

0 commit comments

Comments
 (0)