🎅 2025 Day 12 Complete! 🎄

This commit is contained in:
2025-12-12 07:46:44 -06:00
parent 827f0d8a72
commit fac9e832da
4 changed files with 1326 additions and 0 deletions

1030
2025/day12/input Normal file

File diff suppressed because it is too large Load Diff

78
2025/day12/main.go Normal file
View File

@@ -0,0 +1,78 @@
package main
import (
"bytes"
"fmt"
h "git.bullercodeworks.com/brian/adventofcode/helpers"
)
func main() {
inp := h.StdinToStringSlice()
part1(inp)
fmt.Println()
part2(inp)
}
func part1(inp []string) {
p, r := parseInput(inp)
var acc int
for i := range r {
area := r[i].x * r[i].y
size := 0
for j := range r[i].req {
size += r[i].req[j] * p[j].area
}
if area > size {
acc++
}
}
fmt.Println("Part 1")
fmt.Println(p)
fmt.Println(acc)
}
func part2(inp []string) {
}
type Region struct {
x, y int
req []int
}
type Present struct {
area int
}
func BuildPresent(inp []string) Present {
area := 0
for _, row := range inp {
area += bytes.Count([]byte(row), []byte{'#'})
}
return Present{area: area}
}
func parseInput(inp []string) ([]Present, []Region) {
// All presents are 3x3, we have 6 of them
var presents []Present
var regions []Region
for i := 0; i < 30; i += 5 {
if len(presents) == 6 {
break
}
presents = append(presents, BuildPresent(inp[i+1:i+4]))
}
for i := 30; i < len(inp); i++ {
// Parse regions
r := Region{}
var p0, p1, p2, p3, p4, p5 int
fmt.Sscanf(
inp[i], "%dx%d: %d %d %d %d %d %d",
&r.x, &r.y, &p0, &p1, &p2, &p3, &p4, &p5,
)
r.req = []int{p0, p1, p2, p3, p4, p5}
regions = append(regions, r)
}
return presents, regions
}

185
2025/day12/problem Normal file
View File

@@ -0,0 +1,185 @@
[1]Advent of Code
br0xen [7](AoC++) 24*
--- Day 12: Christmas Tree Farm ---
You're almost out of time, but there can't be much left to decorate.
Although there are no stairs, elevators, escalators, tunnels, chutes,
teleporters, firepoles, or conduits here that would take you deeper into
the North Pole base, there is a ventilation duct. You jump in.
After bumping around for a few minutes, you emerge into a large, well-lit
cavern full of Christmas trees!
There are a few Elves here frantically decorating before the deadline.
They think they'll be able to finish most of the work, but the one thing
they're worried about is the presents for all the young Elves that live
here at the North Pole. It's an ancient tradition to put the presents
under the trees, but the Elves are worried they won't fit.
The presents come in a few standard but very weird shapes. The shapes and
the regions into which they need to fit are all measured in standard
units. To be aesthetically pleasing, the presents need to be placed into
the regions in a way that follows a standardized two-dimensional unit
grid; you also can't stack presents.
As always, the Elves have a summary of the situation (your puzzle input)
for you. First, it contains a list of the presents' shapes. Second, it
contains the size of the region under each tree and a list of the number
of presents of each shape that need to fit into that region. For example:
0:
###
##.
##.
1:
###
##.
.##
2:
.##
###
##.
3:
##.
###
##.
4:
###
#..
###
5:
###
.#.
###
4x4: 0 0 0 0 2 0
12x5: 1 0 1 0 2 2
12x5: 1 0 1 0 3 2
The first section lists the standard present shapes. For convenience, each
shape starts with its index and a colon; then, the shape is displayed
visually, where # is part of the shape and . is not.
The second section lists the regions under the trees. Each line starts
with the width and length of the region; 12x5 means the region is 12 units
wide and 5 units long. The rest of the line describes the presents that
need to fit into that region by listing the quantity of each shape of
present; 1 0 1 0 3 2 means you need to fit one present with shape index 0,
no presents with shape index 1, one present with shape index 2, no
presents with shape index 3, three presents with shape index 4, and two
presents with shape index 5.
Presents can be rotated and flipped as necessary to make them fit in the
available space, but they have to always be placed perfectly on the grid.
Shapes can't overlap (that is, the # part from two different presents
can't go in the same place on the grid), but they can fit together (that
is, the . part in a present's shape's diagram does not block another
present from occupying that space on the grid).
The Elves need to know how many of the regions can fit the presents
listed. In the above example, there are six unique present shapes and
three regions that need checking.
The first region is 4x4:
....
....
....
....
In it, you need to determine whether you could fit two presents that have
shape index 4:
###
#..
###
After some experimentation, it turns out that you can fit both presents in
this region. Here is one way to do it, using A to represent one present
and B to represent the other:
AAA.
ABAB
ABAB
.BBB
The second region, 12x5: 1 0 1 0 2 2, is 12 units wide and 5 units long.
In that region, you need to try to fit one present with shape index 0, one
present with shape index 2, two presents with shape index 4, and two
presents with shape index 5.
It turns out that these presents can all fit in this region. Here is one
way to do it, again using different capital letters to represent all the
required presents:
....AAAFFE.E
.BBBAAFFFEEE
DDDBAAFFCECE
DBBB....CCC.
DDD.....C.C.
The third region, 12x5: 1 0 1 0 3 2, is the same size as the previous
region; the only difference is that this region needs to fit one
additional present with shape index 4. Unfortunately, no matter how hard
you try, there is no way to fit all of the presents into this region.
So, in this example, 2 regions can fit all of their listed presents.
Consider the regions beneath each tree and the presents the Elves would
like to fit into each of them. How many of the regions can fit all of the
presents listed?
Your puzzle answer was 485.
--- Part Two ---
The Elves thank you profusely for the help and start rearranging the
oddly-shaped presents. As you look up, you notice that a lot more Elves
have arrived here at the Christmas tree farm.
In fact, many of these new arrivals look familiar: they're the Elves you
helped while decorating the North Pole base. Right on [16]schedule, each
group seems to have brought a star to put atop one of the Christmas trees!
Before any of them can find a ladder, a particularly large Christmas tree
suddenly flashes brightly when a large star magically appears above it! As
your eyes readjust, you think you notice a portly man with a white beard
disappear into the crowd.
You go look for a ladder; only 23 stars to go.
If you like, you can [17][ [Decorate the North Pole Again] ] .
Both parts of this puzzle are complete! They provide two gold stars: **
At this point, all that is left is for you to [18]admire your Advent
calendar.
References
Visible links
1. https://adventofcode.com/
2. https://adventofcode.com/2025/about
3. https://adventofcode.com/2025/events
4. https://adventofcode.com/2025/shop
5. https://adventofcode.com/2025/settings
6. https://adventofcode.com/2025/auth/logout
7. Advent of Code Supporter
https://adventofcode.com/2025/support
8. https://adventofcode.com/2025
9. https://adventofcode.com/2025
10. https://adventofcode.com/2025/support
11. https://adventofcode.com/2025/sponsors
12. https://adventofcode.com/2025/leaderboard/private
13. https://adventofcode.com/2025/stats
14. https://adventofcode.com/2025/sponsors
15. https://adventofcode.com/2025/sponsors/redirect?url=https%3A%2F%2Fwww%2Eshopify%2Ecom%2Fcareers
16. https://adventofcode.com/2025/day/1
18. https://adventofcode.com/2025
19. https://adventofcode.com/2025/day/12/input

33
2025/day12/testinput Normal file
View File

@@ -0,0 +1,33 @@
0:
###
##.
##.
1:
###
##.
.##
2:
.##
###
##.
3:
##.
###
##.
4:
###
#..
###
5:
###
.#.
###
4x4: 0 0 0 0 2 0
12x5: 1 0 1 0 2 2
12x5: 1 0 1 0 3 2