Skip to content

Commit cf023a8

Browse files
committed
feat(2025): add day 12
1 parent 687063d commit cf023a8

File tree

4 files changed

+156
-13
lines changed

4 files changed

+156
-13
lines changed

go/2025/README.md

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,20 @@ Collect stars by solving puzzles. Two puzzles will be made available on each day
1616

1717
## Days
1818

19-
| Day | #1 | #1 Answer | #2 | #2 Answer |
20-
| ------------------------------------------------------------------------------------------------------------------ | --- | ------------: | --- | --------------: |
21-
| [Day 1: Secret Entrance](https://github.com/believer/advent-of-code/blob/master/go/2025/puzzles/day01/main.go) | 🌟 | 997 | 🌟 | 5978 |
22-
| [Day 2: Gift Shop](https://github.com/believer/advent-of-code/blob/master/go/2025/puzzles/day02/main.go) | 🌟 | 9188031749 | 🌟 | 11323661261 |
23-
| [Day 3: Lobby](https://github.com/believer/advent-of-code/blob/master/go/2025/puzzles/day03/main.go) | 🌟 | 16993 | 🌟 | 168617068915447 |
24-
| [Day 4: Printing Department](https://github.com/believer/advent-of-code/blob/master/go/2025/puzzles/day04/main.go) | 🌟 | 1320 | 🌟 | 8354 |
25-
| [Day 5: Cafeteria](https://github.com/believer/advent-of-code/blob/master/go/2025/puzzles/day05/main.go) | 🌟 | 885 | 🌟 | 348115621205535 |
26-
| [Day 6: Trash Compactor](https://github.com/believer/advent-of-code/blob/master/go/2025/puzzles/day06/main.go) | 🌟 | 6209956042374 | 🌟 | 12608160008022 |
27-
| [Day 7: Laboratories](https://github.com/believer/advent-of-code/blob/master/go/2025/puzzles/day07/main.go) | 🌟 | 1711 | 🌟 | 36706966158365 |
28-
| [Day 8: Playground](https://github.com/believer/advent-of-code/blob/master/go/2025/puzzles/day08/main.go) | 🌟 | 69192 | 🌟 | 7264308110 |
29-
| [Day 9: Movie Theater](https://github.com/believer/advent-of-code/blob/master/go/2025/puzzles/day09/main.go) | 🌟 | 4772103936 | 🌟 | 1529675217 |
30-
| [Day 10: Factory](https://github.com/believer/advent-of-code/blob/master/go/2025/puzzles/day10/main.go) | 🌟 | 455 | | |
31-
| [Day 11: Reactor](https://github.com/believer/advent-of-code/blob/master/go/2025/puzzles/day11/main.go) | 🌟 | 431 | 🌟 | 358458157650450 |
19+
| Day | #1 | #1 Answer | #2 | #2 Answer |
20+
| ------------------------------------------------------------------------------------------------------------------- | --- | ------------: | --- | --------------: |
21+
| [Day 1: Secret Entrance](https://github.com/believer/advent-of-code/blob/master/go/2025/puzzles/day01/main.go) | 🌟 | 997 | 🌟 | 5978 |
22+
| [Day 2: Gift Shop](https://github.com/believer/advent-of-code/blob/master/go/2025/puzzles/day02/main.go) | 🌟 | 9188031749 | 🌟 | 11323661261 |
23+
| [Day 3: Lobby](https://github.com/believer/advent-of-code/blob/master/go/2025/puzzles/day03/main.go) | 🌟 | 16993 | 🌟 | 168617068915447 |
24+
| [Day 4: Printing Department](https://github.com/believer/advent-of-code/blob/master/go/2025/puzzles/day04/main.go) | 🌟 | 1320 | 🌟 | 8354 |
25+
| [Day 5: Cafeteria](https://github.com/believer/advent-of-code/blob/master/go/2025/puzzles/day05/main.go) | 🌟 | 885 | 🌟 | 348115621205535 |
26+
| [Day 6: Trash Compactor](https://github.com/believer/advent-of-code/blob/master/go/2025/puzzles/day06/main.go) | 🌟 | 6209956042374 | 🌟 | 12608160008022 |
27+
| [Day 7: Laboratories](https://github.com/believer/advent-of-code/blob/master/go/2025/puzzles/day07/main.go) | 🌟 | 1711 | 🌟 | 36706966158365 |
28+
| [Day 8: Playground](https://github.com/believer/advent-of-code/blob/master/go/2025/puzzles/day08/main.go) | 🌟 | 69192 | 🌟 | 7264308110 |
29+
| [Day 9: Movie Theater](https://github.com/believer/advent-of-code/blob/master/go/2025/puzzles/day09/main.go) | 🌟 | 4772103936 | 🌟 | 1529675217 |
30+
| [Day 10: Factory](https://github.com/believer/advent-of-code/blob/master/go/2025/puzzles/day10/main.go) | 🌟 | 455 | | |
31+
| [Day 11: Reactor](https://github.com/believer/advent-of-code/blob/master/go/2025/puzzles/day11/main.go) | 🌟 | 431 | 🌟 | 358458157650450 |
32+
| [Day 12: Christmas Tree Farm](https://github.com/believer/advent-of-code/blob/master/go/2025/puzzles/day12/main.go) | 🌟 | 422 | | |
3233

3334
## Benchmarks
3435

@@ -47,6 +48,7 @@ Using Go's built-in benchmarking with the [testing](https://pkg.go.dev/testing#h
4748
| 9 | 593637 | 375621306 | - / `90,43%` |
4849
| 10 | 256756802 | - | |
4950
| 11 | 106015 | 311170 | |
51+
| 12 | 274895 | - | |
5052

5153
All values are ns/op. \* compared to first solution.
5254

go/2025/puzzles/day12/main.go

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
7+
"github.com/believer/aoc-utils/files"
8+
"github.com/believer/aoc-utils/utils"
9+
)
10+
11+
// A bit troll-y :D From reading I thought it was going to be
12+
// impossible. But, I started parsing the list and tried if the
13+
// area would actually fit the size of the shapes and it worked!
14+
15+
func main() {
16+
fmt.Println("Part 1: ", part1("input.txt"))
17+
}
18+
19+
type Region struct {
20+
width, height int
21+
counts []int
22+
}
23+
24+
func (r *Region) Area() int {
25+
return r.width * r.height
26+
}
27+
28+
func part1(name string) (fits int) {
29+
paragraphs := files.ReadParagraphs(name)
30+
31+
// Get size of packages
32+
shapes := []int{}
33+
34+
for _, p := range paragraphs[:6] {
35+
shape := 0
36+
37+
for _, s := range p[1:] {
38+
for v := range strings.SplitSeq(s, "") {
39+
if v == "#" {
40+
shape++
41+
}
42+
}
43+
}
44+
45+
shapes = append(shapes, shape)
46+
}
47+
48+
// Get region sizes and number of packages
49+
packages := [][]int{}
50+
var regions []Region
51+
52+
for _, p := range paragraphs[6:] {
53+
for _, s := range p {
54+
counts := []int{}
55+
region := strings.Fields(s)
56+
area := strings.Split(region[0][:len(region[0])-1], "x")
57+
58+
for _, r := range region[1:] {
59+
counts = append(counts, utils.MustIntFromString(r))
60+
}
61+
62+
packages = append(packages, counts)
63+
64+
regions = append(regions, Region{
65+
height: utils.MustIntFromString(area[0]),
66+
width: utils.MustIntFromString(area[1]),
67+
counts: counts,
68+
})
69+
}
70+
}
71+
72+
// Check if package sizes will fit inside the area
73+
for i, r := range regions {
74+
p := packages[i]
75+
size := 0
76+
77+
for i, pp := range p {
78+
size += shapes[i] * pp
79+
}
80+
81+
if r.Area() >= size {
82+
fits++
83+
}
84+
}
85+
86+
return
87+
}

go/2025/puzzles/day12/main_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package main
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestPart1(t *testing.T) {
10+
t.Run("Part 1", func(t *testing.T) {
11+
expected := 3
12+
actual := part1("test-input.txt")
13+
assert.Equal(t, expected, actual)
14+
})
15+
}
16+
17+
func BenchmarkPart1(b *testing.B) {
18+
for b.Loop() {
19+
part1("input.txt")
20+
}
21+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
0:
2+
###
3+
##.
4+
##.
5+
6+
1:
7+
###
8+
##.
9+
.##
10+
11+
2:
12+
.##
13+
###
14+
##.
15+
16+
3:
17+
##.
18+
###
19+
##.
20+
21+
4:
22+
###
23+
#..
24+
###
25+
26+
5:
27+
###
28+
.#.
29+
###
30+
31+
4x4: 0 0 0 0 2 0
32+
12x5: 1 0 1 0 2 2
33+
12x5: 1 0 1 0 3 2

0 commit comments

Comments
 (0)